Plugin Directory

Changeset 3350045


Ignore:
Timestamp:
08/26/2025 05:12:11 AM (7 months ago)
Author:
softdiscover
Message:

v1.5.0

Location:
softdiscover-db-file-manager/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • softdiscover-db-file-manager/trunk/change_log.txt

    r3344985 r3350045  
     1version 1.5.0
     2[fix] - secure download backup
    13version 1.4.8
    24[update] - support wp 6.8.2
  • softdiscover-db-file-manager/trunk/classes/uiform-form-helper.php

    r3037022 r3350045  
    2929        return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . @$size[$factor];
    3030    }
    31    
     31
    3232    public static function getroute()
    3333    {
     
    5151        return $return;
    5252    }
    53    
     53
    5454    public static function getHttpRequest($var)
    5555    {
     
    6565            $value = isset($_REQUEST[$var]) ? Flmbkp_Form_Helper::sanitizeInput($_REQUEST[$var]) :'';
    6666        }
    67        
     67
    6868        return $value;
    6969    }
    70    
    71    
     70
     71
    7272    public static function array2xml($array, $xml = null)
    7373    {
     
    134134        return $string;
    135135    }
    136    
    137     /**
    138      * Sanitize input 2
     136
     137    /**
     138     * Sanitize input, temporal. it will be removed in future
    139139     *
    140140     * @param string $string input
     
    151151        return $string;
    152152    }
    153    
     153
    154154    /**
    155155     * Sanitize input
     
    169169        return $string;
    170170    }
    171    
    172        
     171
     172
    173173    /**
    174174     * Sanitize input
     
    189189    }
    190190
    191    
     191
    192192    /**
    193193     * Sanitize recursive
     
    205205        }
    206206    }
    207    
     207
    208208    /**
    209209     * Sanitize recursive
     
    221221        }
    222222    }
    223    
     223
    224224
    225225    public static function data_encrypt($string, $key)
     
    318318        return $temp;
    319319    }
    320    
     320
    321321    public static function check_field_length($data, $length)
    322322    {
    323323        return (strlen($data) > intval($length))? substr($data, 0, intval($length)):'';
    324324    }
    325    
     325
    326326    public static function sql_quote($value)
    327327    {
     
    329329            $value = stripslashes($value);
    330330        }
    331        
     331
    332332        $value = addslashes($value);
    333        
     333
    334334        return $value;
    335335    }
    336    
     336
    337337    public static function form_store_fonts($font_temp)
    338338    {
     
    342342        }
    343343    }
    344    
     344
    345345    public static function is_flmbkp_page()
    346346    {
     
    351351            $search=Flmbkp_Form_Helper::sanitizeInput($_POST['page']);
    352352        }
    353        
     353
    354354        $allow=array('flmbkp_file_manager','flmbkp_page_backups','flmbkp_page_database','flmbkp_page_settings');
    355            
     355
    356356        if (in_array($search, $allow)) {
    357357            return true;
     
    360360        }
    361361    }
    362    
     362
    363363    public static function remove_non_tag_space($text)
    364364    {
     
    378378        return $out;
    379379    }
    380    
     380
    381381    public static function assign_alert_container($msg, $type)
    382382    {
     
    404404        return $return_msg;
    405405    }
    406    
     406
    407407    /**
    408408    * Verify if field is checked
     
    419419        }
    420420    }
    421    
     421
    422422    public static function sanitize_output($buffer)
    423423    {
     
    439439        return $buffer;
    440440    }
    441    
    442            
     441
     442
    443443    /**
    444444     * Escape String
     
    458458            return $str;
    459459        }
    460                
     460
    461461        if (!version_compare('5.5', phpversion(), '>=')) {
    462462            $str = addslashes($str);
     
    472472            }
    473473        }
    474                
    475        
    476  
     474
     475
     476
    477477
    478478        return $str;
    479479    }
    480        
    481          
     480
     481
    482482    public static function mysql_version()
    483483    {
    484                
    485            
    486            
    487            
     484
     485
     486
     487
    488488        if (!version_compare('5.5', phpversion(), '>=')) {
    489489             $database_name=DB_NAME;
     
    491491            $datadase_password=DB_PASSWORD;
    492492            $database_host=DB_HOST;
    493                
     493
    494494                $con=mysqli_connect($database_host, $database_user, $datadase_password, $database_name);
    495495                // Check connection
     
    505505        return $str;
    506506    }
    507        
     507
    508508    public static function isValidUrl_structure($url)
    509509    {
     
    520520        return true;
    521521    }
    522        
     522
    523523    public static function json_encode_advanced(array $arr, $sequential_keys = false, $quotes = false, $beautiful_json = false)
    524524    {
     
    556556         return $output;
    557557    }
    558        
     558
    559559    public static function isAssoc(array $arr)
    560560    {
     
    564564        return array_keys($arr) !== range(0, count($arr) - 1);
    565565    }
    566        
     566
    567567    public static function zigaform_user_is_on_admin_page($page_name = 'admin.php')
    568568    {
     
    570570        return ($pagenow == $page_name);
    571571    }
    572        
     572
    573573    public static function get_font_library()
    574574    {
    575575        require_once(FLMBKP_DIR . '/libraries/styles-font-menu/plugin.php');
    576576        $objsfm = new SFM_Plugin();
    577            
     577
    578578        return $objsfm;
    579579    }
    580        
    581            
    582        
     580
     581
     582
    583583        /*
    584584         * Create and get backup directoy
     
    588588
    589589        $backup_dir = WP_CONTENT_DIR.'/uploads/softdiscover';
    590        
     590
    591591        if ((!is_dir($backup_dir) ||
    592592                !is_file($backup_dir.'/index.html') ||
     
    596596            @mkdir($backup_dir, 0775, true);
    597597            @file_put_contents($backup_dir.'/index.html', "<html><body><a href=\"https://softdiscover.com\" target=\"_blank\">WordPress backups by Softdiscover</a></body></html>");
    598                        
     598
    599599            if (!is_file($backup_dir.'/.htaccess')) {
    600600                            @file_put_contents($backup_dir.'/.htaccess', 'deny from all');
    601601            }
    602                        
     602
    603603            if (!is_file($backup_dir.'/web.config')) {
    604604                            @file_put_contents($backup_dir.'/web.config', "<configuration>\n<system.webServer>\n<authorization>\n<deny users=\"*\" />\n</authorization>\n</system.webServer>\n</configuration>\n");
     
    608608        return $backup_dir;
    609609    }
    610        
     610
    611611    public static function get_user_roles()
    612612    {
     
    616616            return $answer;
    617617        }
    618        
    619            
     618
     619
    620620        $user_id = get_current_user_id();
    621        
     621
    622622        if (empty($user_id)) {
    623623            $answer = array('result'=>'error', 'message'=>esc_html__('Wrong request, valid user ID was missed', 'FRocket_admin'));
    624624            return $answer;
    625625        }
    626    
     626
    627627        $user = get_user_by('id', $user_id);
    628628        if (empty($user)) {
     
    630630            return $answer;
    631631        }
    632        
     632
    633633        $other_roles = array_values($user->roles);
    634634        $primary_role = array_shift($other_roles);
    635        
     635
    636636        global $wp_roles;
    637    
     637
    638638        $roles = $wp_roles->roles;
    639639        $roles_main=array();
     
    641641            $roles_main[]=$key;
    642642        }
    643            
     643
    644644        $answer = array('result'=>'success', 'primary_role'=>$primary_role, 'other_roles'=>$roles_main);
    645        
     645
    646646        return $answer;
    647647    }
    648    
     648
    649649    /**
    650650     * Check user access
     
    657657            return false;
    658658        }
    659          
     659
    660660        if ( current_user_can('promote_users')) {
    661661            return true;
    662662        }
    663        
     663
    664664         // make sure the user have manage options
    665665        if (!current_user_can('manage_options')) {
    666666            return false;
    667667        }
    668        
     668
    669669        $user = wp_get_current_user();
    670670        $allowed_roles = get_option('dbflm_fmanager_roles', array());
     
    673673            return false;
    674674        }
    675        
     675
    676676       /* if( !array_intersect($allowed_roles, $user->roles ) ) {
    677677            return false;
    678678        }*/
    679        
    680        
    681        
    682        
    683        
     679
     680
     681
     682
     683
    684684        return true;
    685685    }
    686    
     686
    687687    public static function format_size($rawSize)
    688688    {
     
    697697        }
    698698    }
    699        
    700    
     699
     700
    701701    /*
    702702     * Restore files
  • softdiscover-db-file-manager/trunk/i18n/languages/backend/wprockf.pot

    r3344985 r3350045  
    1 # Copyright (C) 2025 Managefy 1.4.9
    2 # This file is distributed under the same license as the Managefy 1.4.9 package.
     1# Copyright (C) 2025 Managefy 1.5.0
     2# This file is distributed under the same license as the Managefy 1.5.0 package.
    33msgid ""
    44msgstr ""
    5 "Project-Id-Version: Managefy 1.4.9\n"
     5"Project-Id-Version: Managefy 1.5.0\n"
    66"MIME-Version: 1.0\n"
    77"Content-Type: text/plain; charset=UTF-8\n"
    88"Content-Transfer-Encoding: 8bit\n"
    9 "POT-Creation-Date: 2025-08-15 05:52+0000\n"
     9"POT-Creation-Date: 2025-08-26 05:10+0000\n"
    1010"X-Poedit-Basepath: ..\n"
    1111"X-Poedit-KeywordsList: __;_e;_ex:1,2c;_n:1,2;_n_noop:1,2;_nx:1,2,4c;_nx_noop:1,2,3c;_x:1,2c;esc_attr__;esc_attr_e;esc_attr_x:1,2c;esc_html__;esc_html_e;esc_html_x:1,2c\n"
     
    8787msgstr ""
    8888
     89#: modules/filemanager/controllers/backup.php:210
     90msgid "Insufficient permissions."
     91msgstr ""
     92
     93#: modules/filemanager/controllers/backup.php:223, modules/filemanager/controllers/backup.php:230, modules/filemanager/controllers/backup.php:241, modules/filemanager/controllers/backup.php:247
     94msgid "Invalid file requested."
     95msgstr ""
     96
     97#: modules/filemanager/controllers/backup.php:254
     98msgid "Invalid file name."
     99msgstr ""
     100
     101#: modules/filemanager/controllers/backup.php:262
     102msgid "Invalid file type."
     103msgstr ""
     104
     105#: modules/filemanager/controllers/backup.php:271
     106msgid "Backup directory unavailable."
     107msgstr ""
     108
     109#: modules/filemanager/controllers/backup.php:281
     110msgid "Invalid path."
     111msgstr ""
     112
     113#: modules/filemanager/controllers/backup.php:286
     114msgid "File not found."
     115msgstr ""
     116
    89117#: modules/database/views/backend/list_tables.php:27
    90118msgid "Database manager."
  • softdiscover-db-file-manager/trunk/modules/filemanager/controllers/backup.php

    r3037022 r3350045  
    4040    private $pagination = "";
    4141    private $model_backup = "";
    42    
     42
    4343    public $progress;
    4444    public $zip_obj;
    4545    public $last_abort_check;
    46    
    47    
     46
     47
    4848    public $total_targets;
    4949    public $startTime;
     
    5353    public $oFile;
    5454    public $excludes;
    55            
     55
    5656    protected $modules;
    5757    private $per_page = 10;
     
    7171        //create records
    7272        add_action('wp_ajax_flmbkp_backup_createrec', array(&$this, 'ajax_create_records'));
    73        
     73
    7474        //submit header options
    7575        add_action('wp_ajax_flmbkp_backup_sendoptions', array(&$this, 'ajax_submit_options_switch'));
     
    7777        //backup process
    7878        add_action('wp_ajax_flmbkp_backup_watchprogress', array(&$this, 'ajax_watchprogress'));
    79        
     79
    8080        //download file
    8181        add_action('wp_ajax_flmbkp_backup_downloadfile', array(&$this, 'ajax_downloadfile'));
    82        
     82
    8383        //delete record
    8484        add_action('wp_ajax_flmbkp_backup_delete_records', array(&$this, 'ajax_delete_record'));
    85        
     85
    8686        //restore record
    8787        add_action('wp_ajax_flmbkp_backup_restore_records', array(&$this, 'ajax_restore_record'));
    88        
     88
    8989        define('NL', "\r\n");
    9090    }
    91    
    92  
    93      /*
    94      * restore record
    95      */
     91
     92
     93    /*
     94    * restore record
     95    */
    9696    public function ajax_restore_record()
    9797    {
    98        
     98
    9999        check_ajax_referer('flmbkp_ajax_nonce', 'flmbkp_security');
    100        
     100
    101101        $bkp_id = (isset($_POST['rec_id']) && $_POST['rec_id']) ? Flmbkp_Form_Helper::sanitizeInput($_POST['rec_id']) : 0;
    102        
    103        
     102
     103
    104104        $log = array();
    105105        $files_dest = WP_CONTENT_DIR.'/uploads/';
     
    107107            $rec_info=$this->model_backup->getinfo($bkp_id);
    108108            $backup_directory = Flmbkp_Form_Helper::backup_directory();
    109            
     109
    110110            //database
    111111            if (file_exists($backup_directory . '/' . $rec_info->bkp_slug .'_database.zip')) {
    112                     require_once(FLMBKP_DIR . '/classes/uiform_backup.php');
    113                     $objClass = new Flmbkp_Backup($rec_info->bkp_slug, $backup_directory);
     112                require_once(FLMBKP_DIR . '/classes/uiform_backup.php');
     113                $objClass = new Flmbkp_Backup($rec_info->bkp_slug, $backup_directory);
    114114                if ($objClass->restoreBackup($log)) {
    115115                    $log[] = __('<b>Database backup restored.</b>', 'FRocket_admin');
     
    118118                }
    119119            }
    120            
     120
    121121            // Plugins
    122122            if (file_exists($backup_directory . '/' . $rec_info->bkp_slug .'_plugins.zip')) {
     
    128128                }
    129129            }
    130            
     130
    131131            // themes
    132132            if (file_exists($backup_directory . '/' . $rec_info->bkp_slug .'_themes.zip')) {
     
    148148                }
    149149            }
    150            
     150
    151151            // Others
    152152            if (file_exists($backup_directory . '/' . $rec_info->bkp_slug .'_others.zip')) {
     
    159159            }
    160160        }
    161        
     161
    162162        $json = array(
    163163            'log' => $log,
     
    166166            'modal_body'=>self::render_template('filemanager/views/backup/restore_message.php', array('log'=>$log))
    167167        );
    168        
     168
    169169        header('Content-Type: application/json');
    170170        echo json_encode($json);
    171171        wp_die();
    172172    }
    173    
    174      /*
    175      * Delete record
    176      */
     173
     174    /*
     175    * Delete record
     176    */
    177177    public function ajax_delete_record()
    178178    {
    179        
     179
    180180        check_ajax_referer('flmbkp_ajax_nonce', 'flmbkp_security');
    181        
     181
    182182        $bkp_id = (isset($_POST['rec_id']) && $_POST['rec_id']) ? Flmbkp_Form_Helper::sanitizeInput($_POST['rec_id']) : 0;
    183            
     183
    184184        $rec_info=$this->model_backup->getinfo($bkp_id);
    185            
     185
    186186        $backup_directory = Flmbkp_Form_Helper::backup_directory();
    187        
     187
    188188        @unlink($backup_directory . '/' . $rec_info->bkp_slug .'_plugins.zip');
    189189        @unlink($backup_directory . '/' . $rec_info->bkp_slug .'_themes.zip');
     
    191191        @unlink($backup_directory . '/' . $rec_info->bkp_slug .'_others.zip');
    192192        @unlink($backup_directory . '/' . $rec_info->bkp_slug .'_uploads.zip');
    193        
     193
    194194        //de;ete recprd
    195195        $this->wpdb->delete($this->model_backup->table, array( 'bkp_id' => $bkp_id));
    196196    }
    197    
     197
    198198    /*
    199199     * Download file
     200     *
     201     * FIXED: Prevent path traversal and enforce capability checks.
    200202     */
    201203    public function ajax_downloadfile()
    202204    {
    203205        check_ajax_referer('flmbkp_ajax_nonce', 'flmbkp_security');
     206
     207        // Only privileged users may download backups.
     208        if ( ! current_user_can('manage_options') ) {
     209            status_header(403);
     210            wp_die(__('Insufficient permissions.', 'FRocket_admin'));
     211        }
     212
    204213        @set_time_limit(900);
    205         $flm_file = (isset($_GET['flm_file'])) ? Flmbkp_Form_Helper::sanitizeInput_html($_GET['flm_file']) : '';
    206        
    207         $backup_directory=Flmbkp_Form_Helper::backup_directory();
    208         $fullpath = $backup_directory.'/'.$flm_file;
    209        
    210         header("Content-Length: ".filesize($fullpath));
    211         header("Content-type: application/octet-stream");
    212         header("Content-Disposition: attachment; filename=\"".basename($fullpath)."\";");
     214
     215        // Raw input (no HTML decoding) then minimal normalization
     216        $flm_file_raw = isset($_GET['flm_file']) ? wp_unslash($_GET['flm_file']) : '';
     217        // Use your existing helper for generic cleanup, but rely on strict validation below.
     218        $flm_file     = Flmbkp_Form_Helper::sanitizeInput($flm_file_raw);
     219
     220        // Basic presence
     221        if ( ! is_string($flm_file) || $flm_file === '' ) {
     222            status_header(400);
     223            wp_die(__('Invalid file requested.', 'FRocket_admin'));
     224        }
     225
     226        // Must be a basename only (no slashes/backslashes)
     227        $norm = str_replace('\\', '/', $flm_file);
     228        if ( strpos($norm, '/') !== false || basename($norm) !== $norm ) {
     229            status_header(400);
     230            wp_die(__('Invalid file requested.', 'FRocket_admin'));
     231        }
     232
     233        // No control chars / null bytes / traversal tokens / hidden dotfiles
     234        if (
     235            strpos($flm_file, "\0") !== false ||
     236            preg_match('/[[:cntrl:]]/u', $flm_file) ||
     237            preg_match('#(^|[\\/])\.{1,2}([\\/]|$)#', $flm_file) ||
     238            $flm_file[0] === '.'
     239        ) {
     240            status_header(400);
     241            wp_die(__('Invalid file requested.', 'FRocket_admin'));
     242        }
     243
     244        // Reasonable length + strict allowed characters
     245        if ( strlen($flm_file) > 200 || ! preg_match('/^[A-Za-z0-9._-]+$/', $flm_file) ) {
     246            status_header(400);
     247            wp_die(__('Invalid file requested.', 'FRocket_admin'));
     248        }
     249
     250        // (Optional but recommended) enforce expected backup naming pattern
     251        // e.g., flmbkp_YYYYMMDDHHIISS_(plugins|themes|uploads|others|database).zip
     252        if ( ! preg_match('/^flmbkp_\d{14,}_(plugins|themes|uploads|others|database)\.zip$/', $flm_file) ) {
     253            status_header(400);
     254            wp_die(__('Invalid file name.', 'FRocket_admin'));
     255        }
     256
     257        // Allow only specific extensions (backups are produced as .zip)
     258        $allowed_exts = apply_filters('flmbkp_allowed_download_exts', array('zip'));
     259        $ext = strtolower(pathinfo($flm_file, PATHINFO_EXTENSION));
     260        if ( ! in_array($ext, $allowed_exts, true) ) {
     261            status_header(400);
     262            wp_die(__('Invalid file type.', 'FRocket_admin'));
     263        }
     264
     265        // Resolve paths safely
     266        $backup_directory      = Flmbkp_Form_Helper::backup_directory();
     267        $backup_directory_real = realpath($backup_directory);
     268
     269        if ( ! $backup_directory_real || ! is_dir($backup_directory_real) ) {
     270            status_header(500);
     271            wp_die(__('Backup directory unavailable.', 'FRocket_admin'));
     272        }
     273
     274        // Build candidate path within backup directory and resolve
     275        $candidate = $backup_directory_real . DIRECTORY_SEPARATOR . $flm_file;
     276        $fullpath  = realpath($candidate);
     277
     278        // Ensure the resolved path is inside the backup directory
     279        if ( ! $fullpath || strpos($fullpath, $backup_directory_real . DIRECTORY_SEPARATOR) !== 0 ) {
     280            status_header(400);
     281            wp_die(__('Invalid path.', 'FRocket_admin'));
     282        }
     283
     284        if ( ! is_file($fullpath) || ! is_readable($fullpath) ) {
     285            status_header(404);
     286            wp_die(__('File not found.', 'FRocket_admin'));
     287        }
     288
     289        // Stream file to client with safe headers
     290        nocache_headers();
     291        header('Content-Type: application/octet-stream');
     292        header('X-Content-Type-Options: nosniff');
     293        header('Content-Disposition: attachment; filename="' . basename($fullpath) . '";');
     294        header('Content-Length: ' . (string) filesize($fullpath));
     295
     296        if (ob_get_length()) {
     297            @ob_end_clean();
     298        }
     299
    213300        readfile($fullpath);
    214         exit;
    215     }
    216    
     301        exit; // prevent any extra output from corrupting the file
     302    }
     303
    217304    /**
    218305     * list backups
     
    267354
    268355        check_ajax_referer('flmbkp_ajax_nonce', 'flmbkp_security');
    269         $tmp_nexstep = (isset($_POST['nexstep'])) ? urldecode(Flmbkp_Form_Helper::sanitizeInput_html($_POST['nexstep'])) : '';
    270          $tmp_data = (isset($_POST['options'])) ? Flmbkp_Form_Helper::sanitizeInput_html($_POST['options']) : '';
     356
     357        $tmp_data = (isset($_POST['options'])) ? Flmbkp_Form_Helper::sanitizeInput_html($_POST['options']) : '';
    271358        $data2 = array();
    272359        foreach (explode('&', $tmp_data) as $value) {
     
    274361            $data2[] = Flmbkp_Form_Helper::sanitizeInput($value1[1]);
    275362        }
    276        
    277        
     363
     364
    278365        $data=array();
    279366        $data['bkp_slug']='flmbkp_'.date("YmdHis");
     
    287374        $json['url_redirect']=admin_url('admin.php?page=flmbkp_page_backups');
    288375        $json['pending']=$data2;
    289        
     376
    290377        header('Content-Type: application/json');
    291378        echo json_encode($json);
    292379        wp_die();
    293380    }
    294    
    295    
    296     /**
    297     * receiving header options
    298     *
    299     * @mvc Controller
    300     */
     381
     382
     383    /**
     384     * receiving header options
     385     *
     386     * @mvc Controller
     387     */
    301388    public function ajax_submit_options_switch()
    302389    {
    303390        check_ajax_referer('flmbkp_ajax_nonce', 'flmbkp_security');
    304         $tmp_nexstep = (isset($_POST['nexstep'])) ? Flmbkp_Form_Helper::sanitizeInput_html($_POST['nexstep']) : '';
    305            
     391        $tmp_nexstep = (isset($_POST['nexstep'])) ? Flmbkp_Form_Helper::sanitizeInput($_POST['nexstep']) : '';
     392
    306393        switch (strval($tmp_nexstep)) {
    307394            case 'plugins':
    308              //assigning targets
     395                //assigning targets
    309396                $tmp_targets=array(ABSPATH.'/wp-content/plugins');
    310                
     397
    311398                $this->ajax_submit_options($tmp_targets, $tmp_nexstep);
    312399                break;
    313400            case 'themes':
    314              //assigning targets
     401                //assigning targets
    315402                $tmp_targets=array(ABSPATH.'/wp-content/themes');
    316                
     403
    317404                $this->ajax_submit_options($tmp_targets, $tmp_nexstep);
    318405                break;
    319406            case 'uploads':
    320407                $tmp_targets=array(ABSPATH.'/wp-content/uploads');
    321                
     408
    322409                $this->ajax_submit_options($tmp_targets, $tmp_nexstep);
    323410                break;
     
    325412                $tmp_targets=array();
    326413                $tmp_targets=$this->listAndExcludeDIr(ABSPATH.'wp-content', array('uploads','themes','plugins','softdiscover','debug.log'));
    327                
     414
    328415                $this->ajax_submit_options($tmp_targets, $tmp_nexstep);
    329416                break;
     
    336423        }
    337424    }
    338    
     425
    339426    public function mysql_version()
    340427    {
    341            
     428
    342429        if (!version_compare('5.5', phpversion(), '>=')) {
    343              $database_name=DB_NAME;
     430            $database_name=DB_NAME;
    344431            $database_user=DB_USER;
    345432            $datadase_password=DB_PASSWORD;
    346433            $database_host=DB_HOST;
    347                
    348                 $con=mysqli_connect($database_host, $database_user, $datadase_password, $database_name);
    349                 // Check connection
     434
     435            $con=mysqli_connect($database_host, $database_user, $datadase_password, $database_name);
     436            // Check connection
    350437            if (mysqli_connect_errno()) {
    351                // echo "Failed to connect to MySQL: " . mysqli_connect_error();
    352             }
    353 
    354                $str = mysqli_get_server_info($con);
     438                // echo "Failed to connect to MySQL: " . mysqli_connect_error();
     439            }
     440
     441            $str = mysqli_get_server_info($con);
    355442        }else {
    356443            $str = mysql_get_server_info();
     
    359446        return $str;
    360447    }
    361    
     448
    362449    /*
    363450     * backup database
     
    365452    public function ajax_submit_backupdb()
    366453    {
    367         $tmp_flmbkp_slug = (isset($_POST['flmbkp_slug'])) ? urldecode(Flmbkp_Form_Helper::sanitizeInput_html($_POST['flmbkp_slug'])) : 'flmbkp_err'.date("YmdHis");
     454        $tmp_flmbkp_slug = (isset($_POST['flmbkp_slug'])) ? urldecode(Flmbkp_Form_Helper::sanitizeInput($_POST['flmbkp_slug'])) : 'flmbkp_err'.date("YmdHis");
    368455        $this->is_initial_run = !empty($_POST['is_initial_run']);
    369456        require_once FLMBKP_DIR . '/modules/filemanager/helpers/iprogress.php';
    370        
     457
    371458        $backup_directory = Flmbkp_Form_Helper::backup_directory();
    372        
     459
    373460        $this->progress  = new iProgress('zip', 200);
    374          $this->oFile = ($this->is_initial_run || !$this->progress->getData('oFile')) ? $backup_directory . '/' . $tmp_flmbkp_slug .'_database.zip' : $this->progress->getData('oFile');
     461        $this->oFile = ($this->is_initial_run || !$this->progress->getData('oFile')) ? $backup_directory . '/' . $tmp_flmbkp_slug .'_database.zip' : $this->progress->getData('oFile');
    375462        $this->progress->setData('oFile', $this->oFile);
    376        
    377           $dump = '';
    378             $database = DB_NAME;
    379             $server = DB_HOST;
    380           $dump .= '-- --------------------------------------------------------------------------------' . NL;
    381           $dump .= '-- ' . NL;
    382           $dump .= '-- @version: ' . $database . '.sql ' . date('M j, Y') . ' ' . date('H:i') . ' Softdiscover' . NL;
    383           $dump .= '-- @package Database & File Manager' . NL;
    384           $dump .= '-- @author softdiscover.com.' . NL;
    385           $dump .= '-- @copyright 2015' . NL;
    386           $dump .= '-- ' . NL;
    387           $dump .= '-- --------------------------------------------------------------------------------' . NL;
    388           $dump .= '-- Host: ' . $server . NL;
    389           $dump .= '-- Database: ' . $database . NL;
    390           $dump .= '-- Time: ' . date('M j, Y') . '-' . date('H:i') . NL;
    391           $dump .= '-- MySQL version: ' . $this->mysql_version() . NL;
    392           $dump .= '-- PHP version: ' . phpversion() . NL;
    393           $dump .= '-- --------------------------------------------------------------------------------;' . NL . NL;
    394        
    395           $tables = $this->getTables();
     463
     464        $dump = '';
     465        $database = DB_NAME;
     466        $server = DB_HOST;
     467        $dump .= '-- --------------------------------------------------------------------------------' . NL;
     468        $dump .= '-- ' . NL;
     469        $dump .= '-- @version: ' . $database . '.sql ' . date('M j, Y') . ' ' . date('H:i') . ' Softdiscover' . NL;
     470        $dump .= '-- @package Database & File Manager' . NL;
     471        $dump .= '-- @author softdiscover.com.' . NL;
     472        $dump .= '-- @copyright 2015' . NL;
     473        $dump .= '-- ' . NL;
     474        $dump .= '-- --------------------------------------------------------------------------------' . NL;
     475        $dump .= '-- Host: ' . $server . NL;
     476        $dump .= '-- Database: ' . $database . NL;
     477        $dump .= '-- Time: ' . date('M j, Y') . '-' . date('H:i') . NL;
     478        $dump .= '-- MySQL version: ' . $this->mysql_version() . NL;
     479        $dump .= '-- PHP version: ' . phpversion() . NL;
     480        $dump .= '-- --------------------------------------------------------------------------------;' . NL . NL;
     481
     482        $tables = $this->getTables();
    396483        if (!empty($tables)) {
    397484            foreach ($tables as $key => $table) {
    398485                $table_dump = $this->dumpTable($table);
    399                  
     486
    400487                if (!($table_dump)) {
    401488                    return false;
     
    404491            }
    405492        }
    406          
    407        
    408           $fname = $backup_directory;
    409               $fname .= '/'.$tmp_flmbkp_slug .'_database';
    410               $fname .= '.sql';
     493
     494
     495        $fname = $backup_directory;
     496        $fname .= '/'.$tmp_flmbkp_slug .'_database';
     497        $fname .= '.sql';
    411498        if (!($f = fopen($fname, 'w'))) {
    412499            return false;
    413500        }
    414               fwrite($f, $dump);
    415               fclose($f);
    416        
     501        fwrite($f, $dump);
     502        fclose($f);
     503
    417504        $this->zip_obj = new ZipArchive();
    418505        $this->zip_obj->open($this->oFile, ZipArchive::CREATE);
    419506        $this->zip_obj->addFile($fname, basename($fname));
    420507        $this->zip_obj->close();
    421        
     508
    422509        //delete sql file
    423510        unlink($fname);
    424        
     511
    425512        $json = array(
    426513            'error' => false,
     
    430517            'is_finished'=>true
    431518        );
    432        
     519
    433520        header('Content-Type: application/json');
    434521        echo json_encode($json);
    435522        wp_die();
    436523    }
    437    
     524
    438525    public function getTables()
    439526    {
     
    444531        foreach ($result as $mytable) {
    445532            foreach ($mytable as $t) {
    446                      $value[]= $t;
     533                $value[]= $t;
    447534            }
    448535        }
     
    450537            return false;
    451538        }
    452        
     539
    453540        return $value;
    454541    }
    455  
    456    
     542
     543
    457544    public function dumpTable($table)
    458545    {
    459          
    460          // $dump = '';
    461           $this->wpdb->query('LOCK TABLES ' . $table . ' WRITE');
    462          
     546
     547        // $dump = '';
     548        $this->wpdb->query('LOCK TABLES ' . $table . ' WRITE');
     549
    463550        // $tables = $this->wpdb->get_col('SHOW TABLES');
    464551        $output = '';
    465     //foreach($tables as $table) {
     552        //foreach($tables as $table) {
    466553        $result = $this->wpdb->get_results("SELECT * FROM {$table}", ARRAY_N);
    467            
    468                 $output .= '-- --------------------------------------------------' . NL;
    469           $output .= '-- Table structure for table `' . $table . '`' . NL;
    470           $output .= '-- --------------------------------------------------;' . NL;
    471           $output .= 'DROP TABLE IF EXISTS `' . $table . '`;' . NL;
     554
     555        $output .= '-- --------------------------------------------------' . NL;
     556        $output .= '-- Table structure for table `' . $table . '`' . NL;
     557        $output .= '-- --------------------------------------------------;' . NL;
     558        $output .= 'DROP TABLE IF EXISTS `' . $table . '`;' . NL;
    472559        $row2 = $this->wpdb->get_row('SHOW CREATE TABLE '.$table, ARRAY_N);
    473560        $output .= "\n\n".$row2[1].";\n\n";
     
    485572        }
    486573        $output .= "\n";
    487     //}
    488          
    489           $this->wpdb->query('UNLOCK TABLES');
    490           return $output;
     574        //}
     575
     576        $this->wpdb->query('UNLOCK TABLES');
     577        return $output;
    491578    }
    492579    /**
     
    499586
    500587        try {
    501             $is_initial_run = (isset($_POST['is_initial_run'])) ? Flmbkp_Form_Helper::sanitizeInput_html($_POST['is_initial_run']) : 0;
    502             $flush_to_disk = (isset($_POST['flush_to_disk'])) ? Flmbkp_Form_Helper::sanitizeInput_html($_POST['flush_to_disk']) : 50;
    503             $max_execution_time = (isset($_POST['max_execution_time'])) ? Flmbkp_Form_Helper::sanitizeInput_html($_POST['max_execution_time']) : 20;
    504             $tmp_flmbkp_slug = (isset($_POST['flmbkp_slug'])) ? urldecode(Flmbkp_Form_Helper::sanitizeInput_html($_POST['flmbkp_slug'])) : 'flmbkp_err'.date("YmdHis");
     588            $is_initial_run = (isset($_POST['is_initial_run'])) ? Flmbkp_Form_Helper::sanitizeInput($_POST['is_initial_run']) : 0;
     589            $flush_to_disk = (isset($_POST['flush_to_disk'])) ? Flmbkp_Form_Helper::sanitizeInput($_POST['flush_to_disk']) : 50;
     590            $max_execution_time = (isset($_POST['max_execution_time'])) ? Flmbkp_Form_Helper::sanitizeInput($_POST['max_execution_time']) : 20;
     591            $tmp_flmbkp_slug = (isset($_POST['flmbkp_slug'])) ? urldecode(Flmbkp_Form_Helper::sanitizeInput($_POST['flmbkp_slug'])) : 'flmbkp_err'.date("YmdHis");
    505592
    506593            $this->startTime = microtime(true);
    507            
    508         //language
     594
     595            //language
    509596            if (isset($data['flpbkp_opt_files']) && intval($data['flpbkp_opt_files']) === 1) {
    510597                // $this->generate_zip_files();
    511598            }
    512            
     599
    513600            require_once FLMBKP_DIR . '/modules/filemanager/helpers/iprogress.php';
    514        
     601
    515602            $this->progress  = new iProgress('zip', 200);
    516603
     
    525612            $use_system_calls =  false;
    526613            $last_abort_check = microtime(true);
    527        
    528        
    529        
     614
     615
     616
    530617            $targets = ($this->is_initial_run && !empty($tmp_targets)) ? $tmp_targets : $this->progress->getData('targets');
    531        
     618
    532619            if (!$targets) {
    533620                $json['error'] = true;
     
    547634
    548635            clearstatcache(true);
    549        
     636
    550637            foreach ($targets as $target) {
    551638                $path = realpath($target);
     
    563650                }
    564651            }
    565        
     652
    566653            if ($this->is_initial_run) {
    567654                $this->progress->addMsg('Found ' . $this->total_targets . ' items for zipping');
     
    570657
    571658            $backup_directory = Flmbkp_Form_Helper::backup_directory();
    572        
     659
    573660            $this->oFile = ($this->is_initial_run || !$this->progress->getData('oFile')) ? $backup_directory.'/'. $tmp_flmbkp_slug .'_'.$tmp_nexstep. '.zip' : $this->progress->getData('oFile');
    574        
    575        
    576        
     661
     662
     663
    577664            $this->progress->setData('oFile', $this->oFile);
    578        
     665
    579666            chdir(sys_get_temp_dir()); // Zip always get's created in current working dir so move to tmp.
    580667
    581668            $this->zip_obj = new ZipArchive();
    582669            $this->zip_obj->open($this->oFile, ZipArchive::CREATE);
    583            
     670
    584671            $this->iteration_number = 0;
    585672
     
    595682                        $this->stop_iteration();
    596683                    }
    597              
     684
    598685                    set_time_limit(60);
    599686                    if (is_dir($target)) {
     
    608695                        if ($this->iteration_number > $this->progress->getProgress(false)) {
    609696                            $this->progress->addMsg('Adding file "' . $target . '"');
    610                        
     697
    611698                            if (file_exists($target) && is_file($target)) {
    612699                                $this->zip_obj->addFile($target, basename($target));
    613700                            }
    614                        
    615                        
     701
     702
    616703                            $this->progress->iterateWith(1);
    617704
     
    629716            $file_url = FLMBKP_URL . '/' . basename($this->oFile);
    630717            $json = array(
    631             'error' => false,
    632             'continue' => false,
    633             'fileURL' => $file_url,
    634             'is_finished'=>false
     718                'error' => false,
     719                'continue' => false,
     720                'fileURL' => $file_url,
     721                'is_finished'=>false
    635722            );
    636        
     723
    637724            header('Content-Type: application/json');
    638725            echo json_encode($json);
     
    659746    public function listAndExcludeDIr($dir, $exclude = array())
    660747    {
    661        
     748
    662749        if (!is_dir($dir)) {
    663                  return array();
    664         }
    665        
    666            $acceptedfiles=array();
    667             $entries = scandir($dir);
    668             //reads the filenames, one by one
     750            return array();
     751        }
     752
     753        $acceptedfiles=array();
     754        $entries = scandir($dir);
     755        //reads the filenames, one by one
    669756        foreach ($entries as $file) {
    670757            if ($file == '.' || $file == '..') {
    671758                continue;
    672759            }
    673                
     760
    674761            $full_path = $dir.'/'.$file;
    675            
     762
    676763            if (is_dir($full_path) && $file!="." && $file!=".." && !in_array($file, $exclude)) {
    677764                $acceptedfiles[]=$full_path;
     
    681768            }
    682769        }
    683             //closedir($handle);
    684             return $acceptedfiles;
     770        //closedir($handle);
     771        return $acceptedfiles;
    685772    }
    686773    /**
     
    702789            'percent' => $this->progress->getProgressPercent()
    703790        );
    704        
     791
    705792        header('Content-Type: application/json');
    706793        echo json_encode($json);
     
    755842    public function flush_zip()
    756843    {
    757        //$zip=$this->zip_obj;
     844        //$zip=$this->zip_obj;
    758845        $this->zip_obj->close();
    759846        $this->zip_obj->open($this->oFile);
    760        //$this->zip_obj=$zip;
    761     }
    762 
    763    
     847        //$this->zip_obj=$zip;
     848    }
     849
     850
    764851    public function zip_dir($path, $base = '')
    765852    {
    766        
     853
    767854        $progress = $this->progress;
    768            
    769        
     855
     856
    770857        $entries = scandir($path);
    771858
     
    809896        }
    810897    }
    811    
     898
    812899    public function stop_iteration()
    813900    {
     
    854941    {
    855942        //global $use_system_calls;
    856        
     943
    857944        $use_system_calls=false;
    858        
     945
    859946        $path = rtrim($path, '/');
    860947        if ($use_system_calls) {
     
    889976    public function abort_if_requested()
    890977    {
    891        
     978
    892979        $progress = $this->progress;
    893980        $last_abort_check = $this->last_abort_check;
Note: See TracChangeset for help on using the changeset viewer.