Plugin Directory

Changeset 2310129


Ignore:
Timestamp:
05/22/2020 11:09:17 AM (6 years ago)
Author:
DaganLev
Message:

version 1.3.5 released

Location:
really-simple-backup
Files:
4 added
1 deleted
2 edited

Legend:

Unmodified
Added
Removed
  • really-simple-backup/trunk/readme.txt

    r1878475 r2310129  
    33Tags: Simple Backup
    44Requires at least: 3.1
    5 Tested up to: 3.8.1
    6 Stable tag: 1.3.4
     5Tested up to: 5.4.1
     6Stable tag: 1.3.5
    77License: GPLv2 or later
    88License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    5858= 1.3.4 =
    5959Fixed host issues
     60
     61= 1.3.5 =
     62Fixed build issues
  • really-simple-backup/trunk/really-simple-backup.php

    r1878475 r2310129  
    33Plugin Name: Really Simple Backup
    44Description: A simple backup of your Theme, Uploads, Plugins and Database - proceed at your own risk...
    5 Version: 1.3.4
     5Version: 1.3.5
    66Author: Hotscot
    77
     
    2222
    2323*/
    24 
    25 add_action('admin_menu', 'addBackupLink');
    26 
    27 function addBackupLink(){
     24if ( ! defined( 'ABSPATH' ) ) exit('No access'); // disable direct access
     25
     26add_action('admin_menu', 'rsb_addBackupLink');
     27add_action( 'admin_post_rsb_backup_do', 'rsb_backup_response');
     28
     29function rsb_backup_response(){
     30    if(current_user_can('manage_options')){
     31        if( isset($_POST['rsb_timestamp']) && is_numeric($_POST['rsb_timestamp']) && isset( $_POST['rsb_backup_nonce_field'] ) && wp_verify_nonce( $_POST['rsb_backup_nonce_field'], 'rsb_backup_nonce_' . $_POST['rsb_timestamp']) ) {
     32            if(strtotime("Now") - $_POST['rsb_timestamp'] < 300){
     33                // 5 minutes
     34                ini_set('max_execution_time', 3000);
     35                rsb_doBackup();
     36                exit();
     37            }else{
     38                exit('No access');   
     39            }
     40        }else{
     41            exit('No access');
     42        }
     43    }else{
     44        exit('No access');
     45    }
     46}
     47
     48function rsb_addBackupLink(){
    2849    add_submenu_page("index.php",
    2950                     "Really Simple Backup",
     
    3152                     "manage_options",
    3253                     "really-simple-backup",
    33                      "displayBackupPage");
    34 }
    35 
    36 function displayBackupPage(){
    37     ?>
    38     <div class="wrap">
    39         <h2>Really Simple Backup</h2>
    40         <?php if(isset($_POST['backup']) && $_POST['backup'] == '1'):?>
    41             <?php doBackup(); ?>
    42         <?php else: ?>
     54                     "rsb_displayBackupPage");
     55}
     56
     57function rsb_displayBackupPage(){
     58    if(current_user_can('manage_options')){
     59        rsb_cleanup_closed();
     60        ?>
     61        <div class="wrap">
     62            <h2>Really Simple Backup</h2>
    4363            <p>
    4464                Choose from the tick boxes below what you want to backup and then click on the Backup button.<br />
     
    4666                <b>Please Note:<br />when you click the "Backup" a new window will popup and will stay blank for a few minutes,<br />please do not close this window and wait until it prompts for your backup to be downloaded</b>.
    4767            </p>
    48             <form target="_blank" method="post" action="<?php echo WP_PLUGIN_URL; ?>/really-simple-backup/backup.php">
     68            <form target="_blank" method="post" action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>">
     69                <?php
     70                    $timettamp = strtotime("Now");
     71                ?>
     72                <input type="hidden" name="action" value="rsb_backup_do">
     73                <input type="hidden" name="rsb_timestamp" value="<?php echo($timettamp); ?>">
     74                <input type="hidden" name="rsb_backup_nonce_field" value="<?php echo wp_create_nonce( 'rsb_backup_nonce_' . $timettamp ); ?>" />
     75
    4976                <p><input type="checkbox" id="database" name="database" checked="checked" /> Database</p>
    5077                <h2>Uploaded Media</h2>
    5178                <p><input type="checkbox" id="uploadsall" name="uploadsall" /> Download all Uploaded media</p>
    5279                <p>OR Tick individual boxes for the folders below you want to backup from the uploaded media</p>
     80                <ul>
    5381                <?php
    5482                    $iterator = new DirectoryIterator(WP_CONTENT_DIR . '/uploads/');
    5583                    foreach($iterator as $k){
    5684                        if(!preg_match('/\.\.?$/',$k) && !preg_match('/\.svn/',$k) && $k->isDir()){
    57                             echo '<input type="checkbox" id="uploads_'.$k.'" name="uploads[]" value="'. $k .'" /> <label for="uploads_'.$k.'">'. $k .'</label><br />';
     85                            echo '<li><input type="checkbox" id="uploads_'.md5($k).'" name="uploads[]" value="'. md5($k) .'" /> <label for="uploads_'.md5($k).'">'. $k .'</label></li>';
    5886                        }
    5987                    }
    6088                ?>
    61                 <h2>Other Folders</h2>
    62                 <p><input type="checkbox" id="theme" name="theme" /> My Theme</p>
    63                 <p><input type="checkbox" id="plugins" name="plugins" /> Plugins</p>
    64                 <p><input type="checkbox" id="mainfolder" name="mainfolder" /> Other Content Folders</p>
     89                </ul>
    6590                <input type="submit" class="button-primary" value="<?php _e('Backup') ?>" />
    66                 <input type="hidden" name="backup" value="1"/>
    6791            </form>
    68         <?php endif; ?>
    69     </div>
    70     <?php
     92        </div>
     93        <?php
     94    }else{
     95        exit('No access');
     96    }
     97}
     98
     99function rsb_doBackup(){
     100    register_shutdown_function('rsb_cleanup_closed');
     101
     102    $isError = false;
     103    $hash_file = md5($_POST['rsb_backup_nonce_field'] . date('Ymdhis'));
     104    $backupDir = WP_PLUGIN_DIR . '/really-simple-backup/backup/' . $hash_file .'/';
     105    $filename = '';
     106
     107    $backupName = "Backup.zip";
     108
     109    //Supress error if dir already exists
     110    @mkdir($backupDir, 0777);
     111
     112    //Creating mysqldump if requested
     113    $dumpOutput = 0;
     114    if(isset($_POST['database']) && $_POST['database']=='on'){
     115        system('mysqldump -u' . DB_USER . ' -h'. DB_HOST .' -p\'' . DB_PASSWORD . '\' ' . DB_NAME . ' > ' . $backupDir . '/dump_'. $hash_file .'.sql',$dumpOutput);
     116    }
     117   
     118    if($dumpOutput != 0){
     119        $isError = true;
     120        echo 'Error code 1<br />';
     121        if(file_exists($backupDir . '/dump_' . $hash_file . '.sql')) unlink($backupDir . '/dump_'. $hash_file .'.sql');
     122    }else{
     123        if(rsb_zipFolder(WP_CONTENT_DIR, $backupDir . "content_" . $hash_file . ".zip")){
     124            $filename = WP_PLUGIN_DIR . '/really-simple-backup/backup/backup_' . $hash_file . '.zip';
     125            if(rsb_zipFolder_final($backupDir, $filename)){
     126                if(file_exists($backupDir . '/dump_' . $hash_file . '.sql')) unlink($backupDir . '/dump_'. $hash_file .'.sql');
     127                if(file_exists($backupDir . '/content_' . $hash_file . '.zip')) unlink($backupDir . '/content_' . $hash_file . '.zip');
     128                rmdir($backupDir);
     129            }else{
     130                $isError = true;
     131                echo 'Error code 2<br />';
     132                if(file_exists($backupDir . '/dump_' . $hash_file . '.sql')) unlink($backupDir . '/dump_'. $hash_file .'.sql');
     133                if(file_exists($backupDir . '/content_' . $hash_file . '.zip')) unlink($backupDir . '/content_' . $hash_file . '.zip');
     134                rmdir($backupDir);
     135            }
     136        }else{
     137            $isError = true;
     138            echo 'Error code 3<br />';
     139            if(file_exists($backupDir . '/dump_' . $hash_file . '.sql')) unlink($backupDir . '/dump_'. $hash_file .'.sql');
     140            rmdir($backupDir);
     141        }
     142    }
     143
     144    if(!$isError){
     145        if (!is_file($filename) or connection_status()!=0){
     146            echo 'Error code 4<br />';
     147            exit();
     148        }else{
     149            $fsize = (string)(filesize($filename));
     150            header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
     151            header('Content-Description: File Transfer');
     152            header('Content-Type: application/zip');
     153            header("Content-Disposition: attachment; filename=Backup.zip");
     154            header('Content-Transfer-Encoding: binary');
     155            header("Content-Length: ".$fsize);
     156            header("Expires: 0");
     157            header("Pragma: public");
     158
     159            if ($file = fopen($filename, 'rb')) {
     160                while(!feof($file) and (connection_status()==0)) {
     161                    print(fread($file, 1024*8));
     162                    flush();
     163                }
     164                fclose($file);
     165            }
     166            exit();
     167        }
     168    }else{
     169        exit();
     170    }
     171}
     172
     173function rsb_cleanup_closed(){
     174    //clean backup folder
     175    $iterator3 = new DirectoryIterator(WP_PLUGIN_DIR . '/really-simple-backup/backup/');
     176    foreach($iterator3 as $k3){
     177        if(!preg_match('/\.\.?$/',$k3) && !preg_match('/\.svn/',$k3)){
     178            if($k3->isDir()){
     179                if(file_exists(WP_PLUGIN_DIR . '/really-simple-backup/backup/'. $k3 .'/dump_' . $k3 . '.sql')) unlink(WP_PLUGIN_DIR . '/really-simple-backup/backup/'. $k3 .'/dump_' . $k3 . '.sql');
     180                if(file_exists(WP_PLUGIN_DIR . '/really-simple-backup/backup/'. $k3 .'/content_' . $k3 . '.zip')) unlink(WP_PLUGIN_DIR . '/really-simple-backup/backup/'. $k3 .'/content_' . $k3 . '.zip');
     181                rmdir(WP_PLUGIN_DIR . '/really-simple-backup/backup/' . $k3);
     182            }else{
     183                if(file_exists(WP_PLUGIN_DIR . '/really-simple-backup/backup/' . $k3)) unlink(WP_PLUGIN_DIR . '/really-simple-backup/backup/' . $k3);
     184            }
     185        }
     186    }
     187}
     188
     189function rsb_zipFolder($srcDir, $zipFileName){
     190    $tmpZip = new ZipArchive();
     191    $chkState = false;
     192
     193    $zipOutput = $tmpZip->open($zipFileName, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE);
     194
     195    if($zipOutput){
     196        //uploads directory (ALL)
     197        if(isset($_POST['uploadsall']) && $_POST['uploadsall']=='on'){
     198            $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($srcDir . '/uploads/'));
     199            foreach($iterator as $k=>$v){
     200                if(!preg_match('/\.\.?$/',$k) && !preg_match('/\.svn/',$k)){
     201                    $tmpZip->addFile(realpath($k), str_ireplace($srcDir . '/', '', $k));
     202                }
     203            }
     204        }else{
     205            //uploads directory specific folders
     206            if(isset($_POST['uploads']) && is_array($_POST['uploads'])){
     207
     208                $uploadsArr = array();
     209               
     210                // loop through available folders to see which one needs to be added to backup
     211                $iterator = new DirectoryIterator(WP_CONTENT_DIR . '/uploads/');
     212                foreach($iterator as $k2){
     213                    if(!preg_match('/\.\.?$/',$k2) && !preg_match('/\.svn/',$k2) && $k2->isDir()){
     214                        foreach ($_POST['uploads'] as $postedUpload) {
     215                            if(md5($k2) == $postedUpload){
     216                                $uploadsArr[] = $k2->getFilename();
     217                            }
     218                        }
     219                    }
     220                }
     221
     222                if(count($uploadsArr) > 0){
     223                    foreach ($uploadsArr as $postedUpload) {
     224                        $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($srcDir . '/uploads/' . $postedUpload . '/'));
     225                        foreach($iterator as $k=>$v){
     226                            if(!preg_match('/\.\.?$/',$k) && !preg_match('/\.svn/',$k)){
     227                                $tmpZip->addFile(realpath($k), str_ireplace($srcDir . '/', '', $k));
     228                            }
     229                        }
     230                    }
     231                }
     232            }
     233        }
     234
     235        $tmpZip->close();
     236        $chkState = true;
     237    }else{
     238        echo 'Error code 5<br />';
     239        $chkState = false;
     240    }
     241
     242    return $chkState;
     243}
     244
     245function rsb_zipFolder_final($srcDir, $zipFileName){
     246    $tmpZip = new ZipArchive();
     247    $chkState = false;
     248
     249    $zipOutput = $tmpZip->open($zipFileName, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE);
     250
     251    if($zipOutput){
     252        $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($srcDir));
     253        foreach($iterator as $k=>$v){
     254            if(!preg_match('/\.\.?$/',$k) && !preg_match('/\.svn/',$k)){
     255                $tmpZip->addFile(realpath($k), str_ireplace($srcDir, '', $k));
     256            }
     257        }
     258        $tmpZip->close();
     259        $chkState = true;
     260    }else{
     261        echo 'Error code 6<br />';
     262        $chkState = false;
     263    }
     264
     265    return $chkState;
    71266}
    72267?>
Note: See TracChangeset for help on using the changeset viewer.