Backup and Restore WordPress – WPBackItUp Backup Plugin - Version 1.9.2

Version Description

  • New Features: Added WordPress 4.0.1 support
  • New Features: Major Security Enhancements
  • New Features: Added log attachment to backup notification email
  • Update: Moved zip threshold to constant.
  • Update: Added additional logging to archive process
Download this release

Release Info

Developer cssimmon
Plugin Icon 128x128 Backup and Restore WordPress – WPBackItUp Backup Plugin
Version 1.9.2
Comparing to
See all releases

Code changes from version 1.9.1 to 1.9.2

js/wpbackitup_admin.js CHANGED
@@ -11,10 +11,8 @@
11
  //Add View Log Click event to backup page
12
  wpbackitup_add_viewlog_onclick();
13
 
14
- ///* define logreader variables */
15
- //var wpbackitup_backup_response_reader = {
16
- // action: wpbackitup_get_action_name('backup_response_reader')
17
- //};
18
 
19
  /* define logreader variables */
20
  var wpbackitup_restore_status_reader = {
@@ -75,6 +73,15 @@
75
  });
76
  }
77
 
 
 
 
 
 
 
 
 
 
78
  /* get restore status */
79
  function wpbackitup_get_restore_status() {
80
  $.post(ajaxurl, wpbackitup_restore_status_reader, function(response) {
@@ -645,17 +652,17 @@
645
  // built id of the row to be inserted dynamically
646
  if (typeof data !== 'undefined')
647
  {
648
- var restoreColumn = '<td><a href="#" title="' + data.backupFile + '" class="restoreRow" id="restoreRow' + cur_row + '">Restore</a></td>\n';
649
 
650
  var viewColumn = '<td>&nbsp;</td>\n';
651
- if (typeof data.backupLogLink !== 'undefined') {
652
- viewColumn = '<td><a class="viewloglink" href="' + data.backupLogLink + '">View Log</a></td>\n';
653
  }
654
 
655
  var newRow =
656
  '<tr ' + css_class + ' id="row' + cur_row + '">\n\
657
  <td>New Backup!</td>\n\
658
- <td><a href="' + data.backupZipLink + '">Download</a></td>\n';
659
  newRow +=viewColumn;
660
  newRow +='<td><a href="#" title="' + data.backupFile + '" class="deleteRow" id="deleteRow' + cur_row + '">Delete</a></td>\n';
661
  newRow +='</tr>';
@@ -672,6 +679,8 @@
672
 
673
  wpbackitup_add_viewlog_onclick();
674
 
 
 
675
  }
676
  }
677
 
11
  //Add View Log Click event to backup page
12
  wpbackitup_add_viewlog_onclick();
13
 
14
+ //Add download backup Click event to backup page
15
+ wpbackitup_add_downloadbackup_onclick();
 
 
16
 
17
  /* define logreader variables */
18
  var wpbackitup_restore_status_reader = {
73
  });
74
  }
75
 
76
+ function wpbackitup_add_downloadbackup_onclick(){
77
+ $(".downloadbackuplink").click(function(){
78
+ var href = $(this).attr("href");
79
+ $("#backup_name").val(href);
80
+ $("#download_backup").submit();
81
+ return false;
82
+ });
83
+ }
84
+
85
  /* get restore status */
86
  function wpbackitup_get_restore_status() {
87
  $.post(ajaxurl, wpbackitup_restore_status_reader, function(response) {
652
  // built id of the row to be inserted dynamically
653
  if (typeof data !== 'undefined')
654
  {
655
+ //var restoreColumn = '<td><a href="#" title="' + data.backupFile + '" class="restoreRow" id="restoreRow' + cur_row + '">Restore</a></td>\n';
656
 
657
  var viewColumn = '<td>&nbsp;</td>\n';
658
+ if (typeof data.logFileExists !== 'undefined' && data.logFileExists==true) {
659
+ viewColumn = '<td><a class="viewloglink" href="' + data.backupFile + '">View Log</a></td>\n';
660
  }
661
 
662
  var newRow =
663
  '<tr ' + css_class + ' id="row' + cur_row + '">\n\
664
  <td>New Backup!</td>\n\
665
+ <td><a class="downloadbackuplink" href="' + data.backupFile + '">Download</a></td>\n';
666
  newRow +=viewColumn;
667
  newRow +='<td><a href="#" title="' + data.backupFile + '" class="deleteRow" id="deleteRow' + cur_row + '">Delete</a></td>\n';
668
  newRow +='</tr>';
679
 
680
  wpbackitup_add_viewlog_onclick();
681
 
682
+ wpbackitup_add_downloadbackup_onclick();
683
+
684
  }
685
  }
686
 
lib/includes/class-backup.php CHANGED
@@ -215,6 +215,9 @@ class WPBackItUp_Backup {
215
  //Purge cleanup logs in logs older than 5 days
216
  $fileSystem->purge_files($logs_path,'*cleanup*.log',$this->backup_retained_days);
217
 
 
 
 
218
  //Purge restore logs in logs older than 5 days
219
  $fileSystem->purge_files($logs_path,'*restore*.log',$this->backup_retained_days);
220
 
@@ -231,12 +234,12 @@ class WPBackItUp_Backup {
231
  return false;
232
  }
233
 
234
- //create index.html
235
- $backup_index = $this->backup_folder_root .'/index.html';
236
- if( !is_file($backup_index) ) {
237
- $dfh = fopen( $backup_index, 'a' );
238
- fclose( $dfh );
239
- }
240
 
241
  $this->logger->log_info(__METHOD__,'End');
242
  return true;
215
  //Purge cleanup logs in logs older than 5 days
216
  $fileSystem->purge_files($logs_path,'*cleanup*.log',$this->backup_retained_days);
217
 
218
+ //Purge Zipped logs in logs older than 5 days
219
+ $fileSystem->purge_files($logs_path,'logs_*.zip',$this->backup_retained_days);
220
+
221
  //Purge restore logs in logs older than 5 days
222
  $fileSystem->purge_files($logs_path,'*restore*.log',$this->backup_retained_days);
223
 
234
  return false;
235
  }
236
 
237
+ $fileSystem->secure_folder($this->backup_folder_root);
238
+
239
+ //Make sure logs folder is secured
240
+ $logs_dir = WPBACKITUP__PLUGIN_PATH .'/logs/';
241
+ $fileSystem->secure_folder( $logs_dir);
242
+
243
 
244
  $this->logger->log_info(__METHOD__,'End');
245
  return true;
lib/includes/class-filesystem.php CHANGED
@@ -18,9 +18,13 @@ class WPBackItUp_FileSystem {
18
 
19
  private $logger;
20
 
21
- function __construct($logger) {
22
  try {
23
- $this->logger = $logger;
 
 
 
 
24
  } catch(Exception $e) {
25
  //Dont do anything
26
  print $e;
@@ -438,4 +442,28 @@ class WPBackItUp_FileSystem {
438
  }
439
  }
440
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
441
  }
18
 
19
  private $logger;
20
 
21
+ function __construct($logger=null) {
22
  try {
23
+ if (null==$logger){
24
+ $this->logger = new WPBackItUp_Logger(true,null,'debug_filesystem');
25
+ } else{
26
+ $this->logger = $logger;
27
+ }
28
  } catch(Exception $e) {
29
  //Dont do anything
30
  print $e;
442
  }
443
  }
444
 
445
+ /**
446
+ * Make sure that htaccess/web.config files exist in folder
447
+ * If folder doesnt exist then create it.
448
+ * @param $path
449
+ */
450
+ function secure_folder($path){
451
+ $this->logger->log_info(__METHOD__,'Begin');
452
+
453
+ $path = rtrim($path,"/");
454
+
455
+ if( !is_dir($path) ) {
456
+ @mkdir($path, 0755);
457
+ $this->logger->log_info(__METHOD__,'Folder Created:' .$path);
458
+ }
459
+
460
+ if (!is_file($path.'/index.html')) @file_put_contents($path.'/index.html',"<html><body><a href=\"http://www.wpbackitup.com\">WP BackItUp - The simplest way to backup WordPress</a></body></html>");
461
+ if (!is_file($path.'/.htaccess')) @file_put_contents($path.'/.htaccess','deny from all');
462
+ if (!is_file($path.'/web.config')) @file_put_contents($path.'/web.config', "<configuration>\n<system.webServer>\n<authorization>\n<deny users=\"*\" />\n</authorization>\n</system.webServer>\n</configuration>\n");
463
+ $this->logger->log_info(__METHOD__,'Secure files exist or were created.');
464
+
465
+
466
+ $this->logger->log_info(__METHOD__,'End');
467
+ }
468
+
469
  }
lib/includes/class-utility.php CHANGED
@@ -25,7 +25,7 @@ class WPBackItUp_Utility {
25
  }
26
 
27
 
28
- function send_email($to,$subject,$message)
29
  {
30
  try {
31
  //global $WPBackitup;
@@ -34,7 +34,7 @@ class WPBackItUp_Utility {
34
  $headers[] = 'Content-type: text/html';
35
  $headers[] = 'From: WP BackItUp '. '<'. $from_email .'>';
36
 
37
- wp_mail($to, $subject, $message, $headers);
38
  $this->logger->log('(send_email)EMail Sent from:' .$from_email);
39
  $this->logger->log('(send_email)EMail Sent to:' .$to);
40
  }
25
  }
26
 
27
 
28
+ function send_email($to,$subject,$message,$attachments=array())
29
  {
30
  try {
31
  //global $WPBackitup;
34
  $headers[] = 'Content-type: text/html';
35
  $headers[] = 'From: WP BackItUp '. '<'. $from_email .'>';
36
 
37
+ wp_mail($to, $subject, $message, $headers,$attachments);
38
  $this->logger->log('(send_email)EMail Sent from:' .$from_email);
39
  $this->logger->log('(send_email)EMail Sent to:' .$to);
40
  }
lib/includes/class-wpbackitup-admin.php CHANGED
@@ -130,6 +130,9 @@ class WPBackitup_Admin {
130
  //View Log Action
131
  add_action('admin_post_viewlog', array( &$this,'admin_viewlog'));
132
 
 
 
 
133
  //List Logs Action
134
  add_action('admin_post_nopriv_listlogs', array( &$this,'admin_listlogs'));
135
 
@@ -304,6 +307,9 @@ class WPBackitup_Admin {
304
 
305
  public function wpbackitup_queue_scheduled_jobs(){
306
 
 
 
 
307
  //Include Scheduler Class
308
  if( !class_exists( 'WPBackItUp_Scheduler' ) ) {
309
  include_once 'class-scheduler.php';
@@ -361,6 +367,9 @@ class WPBackitup_Admin {
361
 
362
  //Run queue manual backup
363
  public function ajax_queue_backup() {
 
 
 
364
  $logger = new WPBackItUp_Logger(false,null,'debug_events');
365
  $logger->log_info(__METHOD__,'Begin');
366
 
@@ -389,6 +398,10 @@ class WPBackitup_Admin {
389
 
390
  //Run scheduled backup tasks
391
  function wpbackitup_run_backup_tasks(){
 
 
 
 
392
  $process_id = uniqid();
393
 
394
  $event_logger = new WPBackItUp_Logger(false,null,'debug_events');
@@ -407,6 +420,9 @@ class WPBackitup_Admin {
407
 
408
  //Run scheduled backup tasks
409
  function wpbackitup_run_cleanup_tasks(){
 
 
 
410
  $process_id = uniqid();
411
 
412
  $event_logger = new WPBackItUp_Logger(false,null,'debug_events');
@@ -425,6 +441,9 @@ class WPBackitup_Admin {
425
 
426
 
427
  public function ajax_get_restore_status() {
 
 
 
428
  $log = WPBACKITUP__PLUGIN_PATH .'/logs/restore_status.log';
429
  if(file_exists($log) ) {
430
  readfile($log);
@@ -437,25 +456,37 @@ class WPBackitup_Admin {
437
  * Return the backup status and try run tasks
438
  */
439
  public function ajax_get_backup_status() {
440
- $process_id = uniqid();
 
441
 
442
  $event_logger = new WPBackItUp_Logger(false,null,'debug_events');
443
- $event_logger->log_info(__METHOD__ .'(' .$process_id .')', 'Begin');
444
 
445
- //Try Run Next Backup Tasks
446
- $event_logger->log_info(__METHOD__.'(' .$process_id .')','Try Run Backup Task');
447
 
448
- $this->backup_type='manual';
449
- include_once( WPBACKITUP__PLUGIN_PATH.'/lib/includes/job_backup.php' );
 
450
 
451
- $event_logger->log_info(__METHOD__.'(' .$process_id .')','End Try Run Backup Task');
452
 
453
- //return status
454
- $log = WPBACKITUP__PLUGIN_PATH .'/logs/backup_status.log';
455
- if(file_exists($log) ) {
456
- //Probably should use the database instead now.
457
- readfile($log);
458
- $event_logger->log_info(__METHOD__.'(' .$process_id .')','Status sent to browser.');
 
 
 
 
 
 
 
 
 
 
 
 
459
  }
460
 
461
  exit;
@@ -463,17 +494,26 @@ class WPBackitup_Admin {
463
 
464
  //load restore
465
  public function ajax_restore() {
 
 
 
466
  include_once( WPBACKITUP__PLUGIN_PATH.'/lib/includes/job_restore.php' );
467
  }
468
 
469
  //load upload
470
  public function ajax_upload() {
 
 
 
471
  include_once( WPBACKITUP__PLUGIN_PATH.'/lib/includes/upload.php' );
472
  }
473
 
474
 
475
 
476
  public function ajax_backup_response_reader() {
 
 
 
477
  $log = WPBACKITUP__PLUGIN_PATH .'/logs/backup_response.log';
478
  if(file_exists($log) ) {
479
  readfile($log);
@@ -487,6 +527,9 @@ class WPBackitup_Admin {
487
 
488
  public function ajax_delete_file()
489
  {
 
 
 
490
  $backup_file_name = str_replace('deleteRow', '', $_POST['filed']);
491
  $backup_file_path = WPBACKITUP__BACKUP_PATH .'/' . $backup_file_name;
492
  $log_file_path = str_replace('.zip','.log',$backup_file_path);
@@ -503,11 +546,21 @@ class WPBackitup_Admin {
503
  }
504
 
505
  function admin_viewlog(){
 
 
506
  include_once( WPBACKITUP__PLUGIN_PATH.'/lib/includes/viewlog.php' );
507
  }
508
 
 
 
 
 
 
 
509
  function admin_listlogs(){
510
- include_once( WPBACKITUP__PLUGIN_PATH.'/lib/includes/listlogs.php' );
 
 
511
  }
512
 
513
 
@@ -1230,6 +1283,36 @@ class WPBackitup_Admin {
1230
 
1231
  /**STATIC FUNCTIONS**/
1232
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1233
  private static function get_settings_page_url( $page = 'config' ) {
1234
 
1235
  $args = array( 'page' => 'wp-backitup-settings' );
@@ -1252,47 +1335,20 @@ class WPBackitup_Admin {
1252
  wp_schedule_event( time()+3600, 'hourly', 'wpbackitup_queue_scheduled_jobs');
1253
  }
1254
 
1255
- //Check backup folder folders
1256
- $backup_dir = WPBACKITUP__CONTENT_PATH . '/' . WPBACKITUP__BACKUP_FOLDER;
1257
- if( !is_dir($backup_dir) ) {
1258
- @mkdir($backup_dir, 0755);
1259
- }
1260
-
1261
- //Check index in backup
1262
- $backup_index = $backup_dir .'/index.html';
1263
- if( !is_file($backup_index) ) {
1264
- //create index.html
1265
- $dfh = fopen( $backup_index, 'a' );
1266
- fclose( $dfh );
1267
- }
1268
 
1269
- //Check restore folder folders
1270
  $restore_dir = WPBACKITUP__CONTENT_PATH . '/' . WPBACKITUP__RESTORE_FOLDER;
1271
- if( !is_dir($restore_dir) ) {
1272
- @mkdir($restore_dir, 0755);
1273
- }
1274
-
1275
- //check index in restore
1276
- $restore_index = $restore_dir .'/index.html';
1277
- if( !is_file($restore_index) ) {
1278
- //create index.html
1279
- $dfh = fopen( $restore_index, 'a' );
1280
- fclose( $dfh );
1281
- }
1282
 
1283
- //Check permissions on logs
1284
- $logs_dir = WPBACKITUP__PLUGIN_PATH .'/logs';
1285
- if(is_dir($logs_dir) ) {
1286
- chmod($logs_dir, 0755);
1287
- }
1288
-
1289
- //check index in logs
1290
- $logs_index = $logs_dir .'/index.html';
1291
- if( !is_file($logs_index) ) {
1292
- //create index.html
1293
- $dfh = fopen( $logs_index, 'a' );
1294
- fclose( $dfh );
1295
- }
1296
 
1297
  //Make sure they exist now
1298
  if( !is_dir($backup_dir) || !is_dir($restore_dir)) {
130
  //View Log Action
131
  add_action('admin_post_viewlog', array( &$this,'admin_viewlog'));
132
 
133
+ //Download Backup
134
+ add_action('admin_post_download_backup', array( &$this,'admin_download_backup'));
135
+
136
  //List Logs Action
137
  add_action('admin_post_nopriv_listlogs', array( &$this,'admin_listlogs'));
138
 
307
 
308
  public function wpbackitup_queue_scheduled_jobs(){
309
 
310
+ // Check permissions
311
+ if (! self::is_authorized()) exit('Access denied.');
312
+
313
  //Include Scheduler Class
314
  if( !class_exists( 'WPBackItUp_Scheduler' ) ) {
315
  include_once 'class-scheduler.php';
367
 
368
  //Run queue manual backup
369
  public function ajax_queue_backup() {
370
+ // Check permissions
371
+ if (! self::is_authorized()) exit('Access denied.');
372
+
373
  $logger = new WPBackItUp_Logger(false,null,'debug_events');
374
  $logger->log_info(__METHOD__,'Begin');
375
 
398
 
399
  //Run scheduled backup tasks
400
  function wpbackitup_run_backup_tasks(){
401
+
402
+ // Check permissions
403
+ if (! self::is_authorized()) exit('Access denied.');
404
+
405
  $process_id = uniqid();
406
 
407
  $event_logger = new WPBackItUp_Logger(false,null,'debug_events');
420
 
421
  //Run scheduled backup tasks
422
  function wpbackitup_run_cleanup_tasks(){
423
+ // Check permissions
424
+ if (! self::is_authorized()) exit('Access denied.');
425
+
426
  $process_id = uniqid();
427
 
428
  $event_logger = new WPBackItUp_Logger(false,null,'debug_events');
441
 
442
 
443
  public function ajax_get_restore_status() {
444
+ // Check permissions
445
+ if (! self::is_authorized()) exit('Access denied.');
446
+
447
  $log = WPBACKITUP__PLUGIN_PATH .'/logs/restore_status.log';
448
  if(file_exists($log) ) {
449
  readfile($log);
456
  * Return the backup status and try run tasks
457
  */
458
  public function ajax_get_backup_status() {
459
+ // Check permissions
460
+ if (! self::is_authorized()) exit('Access denied.');
461
 
462
  $event_logger = new WPBackItUp_Logger(false,null,'debug_events');
 
463
 
464
+ $event_logger->log_info(__METHOD__ ,'User Permissions: ' .current_user_can( 'manage_options' ));
 
465
 
466
+ //Check permissions
467
+ if ( current_user_can( 'manage_options' ) ) {
468
+ //echo('RUNNING BACKUP');
469
 
470
+ $process_id = uniqid();
471
 
472
+
473
+ $event_logger->log_info(__METHOD__ .'(' .$process_id .')', 'Begin');
474
+
475
+ //Try Run Next Backup Tasks
476
+ $event_logger->log_info(__METHOD__.'(' .$process_id .')','Try Run Backup Task');
477
+
478
+ $this->backup_type='manual';
479
+ include_once( WPBACKITUP__PLUGIN_PATH.'/lib/includes/job_backup.php' );
480
+
481
+ $event_logger->log_info(__METHOD__.'(' .$process_id .')','End Try Run Backup Task');
482
+
483
+ //return status
484
+ $log = WPBACKITUP__PLUGIN_PATH .'/logs/backup_status.log';
485
+ if(file_exists($log) ) {
486
+ //Probably should use the database instead now.
487
+ readfile($log);
488
+ $event_logger->log_info(__METHOD__.'(' .$process_id .')','Status sent to browser.');
489
+ }
490
  }
491
 
492
  exit;
494
 
495
  //load restore
496
  public function ajax_restore() {
497
+ // Check permissions
498
+ if (! self::is_authorized()) exit('Access denied.');
499
+
500
  include_once( WPBACKITUP__PLUGIN_PATH.'/lib/includes/job_restore.php' );
501
  }
502
 
503
  //load upload
504
  public function ajax_upload() {
505
+ // Check permissions
506
+ if (! self::is_authorized()) exit('Access denied.');
507
+
508
  include_once( WPBACKITUP__PLUGIN_PATH.'/lib/includes/upload.php' );
509
  }
510
 
511
 
512
 
513
  public function ajax_backup_response_reader() {
514
+ // Check permissions
515
+ if (! self::is_authorized()) exit('Access denied.');
516
+
517
  $log = WPBACKITUP__PLUGIN_PATH .'/logs/backup_response.log';
518
  if(file_exists($log) ) {
519
  readfile($log);
527
 
528
  public function ajax_delete_file()
529
  {
530
+ // Check permissions
531
+ if (! self::is_authorized()) exit('Access denied.');
532
+
533
  $backup_file_name = str_replace('deleteRow', '', $_POST['filed']);
534
  $backup_file_path = WPBACKITUP__BACKUP_PATH .'/' . $backup_file_name;
535
  $log_file_path = str_replace('.zip','.log',$backup_file_path);
546
  }
547
 
548
  function admin_viewlog(){
549
+ if (! self::is_authorized()) exit('Access denied.');
550
+
551
  include_once( WPBACKITUP__PLUGIN_PATH.'/lib/includes/viewlog.php' );
552
  }
553
 
554
+ function admin_download_backup(){
555
+ if (! self::is_authorized()) exit('Access denied.');
556
+
557
+ include_once( WPBACKITUP__PLUGIN_PATH.'/lib/includes/download_backup.php' );
558
+ }
559
+
560
  function admin_listlogs(){
561
+ if (! self::is_authorized()) exit('Access denied.');
562
+
563
+ include_once( WPBACKITUP__PLUGIN_PATH.'/lib/includes/listlogs.php' );
564
  }
565
 
566
 
1283
 
1284
  /**STATIC FUNCTIONS**/
1285
 
1286
+ public static function is_authorized(){
1287
+
1288
+ $permission_logger = new WPBackItUp_Logger(false,null,'debug_permissions');
1289
+ $permission_logger->log_info(__METHOD__ ,'Begin');
1290
+
1291
+ $permission_logger->log_info(__METHOD__ ,'User Permissions: ' .current_user_can( 'manage_options' ));
1292
+
1293
+ if (defined('DOING_CRON')) {
1294
+ $permission_logger->log_info( __METHOD__, 'Doing CRON Constant: ' . DOING_CRON );
1295
+ } else {
1296
+ $permission_logger->log_info(__METHOD__ ,'DOING_CRON - NOT defined');
1297
+ }
1298
+
1299
+ if (defined('XMLRPC_REQUEST')) {
1300
+ $permission_logger->log_info(__METHOD__ ,'XMLRPC_REQUEST Constant: ' .XMLRPC_REQUEST );
1301
+ } else {
1302
+ $permission_logger->log_info(__METHOD__ ,'XMLRPC_REQUEST - NOT defined ');
1303
+ }
1304
+
1305
+ //Check User Permissions or CRON
1306
+ if (!current_user_can( 'manage_options' )
1307
+ && (!defined('DOING_CRON') || !DOING_CRON)){
1308
+ $permission_logger->log_info(__METHOD__ ,'End - NOT AUTHORIZED');
1309
+ return false;
1310
+ }
1311
+
1312
+ $permission_logger->log_info(__METHOD__ ,'End - SUCCESS');
1313
+ return true;
1314
+ }
1315
+
1316
  private static function get_settings_page_url( $page = 'config' ) {
1317
 
1318
  $args = array( 'page' => 'wp-backitup-settings' );
1335
  wp_schedule_event( time()+3600, 'hourly', 'wpbackitup_queue_scheduled_jobs');
1336
  }
1337
 
1338
+ require_once( WPBACKITUP__PLUGIN_PATH .'/lib/includes/class-filesystem.php' );
1339
+ $file_system = new WPBackItUp_FileSystem();
1340
+
1341
+ //Check backup folder folders
1342
+ $backup_dir = WPBACKITUP__CONTENT_PATH . '/' . WPBACKITUP__BACKUP_FOLDER;
1343
+ $file_system->secure_folder( $backup_dir);
1344
+
 
 
 
 
 
 
1345
 
1346
+ //--Check restore folder folders
1347
  $restore_dir = WPBACKITUP__CONTENT_PATH . '/' . WPBACKITUP__RESTORE_FOLDER;
1348
+ $file_system->secure_folder( $restore_dir);
 
 
 
 
 
 
 
 
 
 
1349
 
1350
+ $logs_dir = WPBACKITUP__PLUGIN_PATH .'/logs/';
1351
+ $file_system->secure_folder( $logs_dir);
 
 
 
 
 
 
 
 
 
 
 
1352
 
1353
  //Make sure they exist now
1354
  if( !is_dir($backup_dir) || !is_dir($restore_dir)) {
lib/includes/class-zip.php CHANGED
@@ -1 +1 @@
1
- <?php if (!defined ('ABSPATH')) die('No direct access allowed');
2
  * WP Backitup Zip Function
3
  *
4
  * @package WP Backitup
5
  *
6
  * @author cssimmon
7
  *
8
  */
9
  private $zip_file_count;
10
  private $max_file_count=1000;
11
  $this->zip_file_count=0;
12
  }
13
  function __destruct() {
 
14
  * WP Backitup Zip Function
15
  *
16
  * @package WP Backitup
17
  *
18
  * @author cssimmon
19
  *
20
  */
21
  private $zip_file_count;
22
  private $max_file_count;
23
  $this->zip_file_count=0;
24
  }
25
  function __destruct() {
 
1
  * WP Backitup Zip Function
2
  *
3
  * @package WP Backitup
4
  *
5
  * @author cssimmon
6
  *
7
  */
8
  private $zip_file_count;
9
  private $max_file_count=1000;
10
  $this->zip_file_count=0;
11
  }
12
  function __destruct() {
13
+ <?php if (!defined ('ABSPATH')) die('No direct access allowed');
14
  * WP Backitup Zip Function
15
  *
16
  * @package WP Backitup
17
  *
18
  * @author cssimmon
19
  *
20
  */
21
  private $zip_file_count;
22
  private $max_file_count;
23
  $this->zip_file_count=0;
24
  }
25
  function __destruct() {
lib/includes/download_backup.php ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php if (!defined ('ABSPATH')) die('No direct access allowed (viewlog)');
2
+
3
+
4
+ if ( isset($_REQUEST['_wpnonce']) && !empty($_REQUEST['_wpnonce'])
5
+ && isset($_REQUEST['backup_name']) && !empty($_REQUEST['backup_name']) ){
6
+
7
+ if ( wp_verify_nonce($_REQUEST['_wpnonce'],WPBACKITUP__NAMESPACE .'-download_backup')) {
8
+
9
+ // make sure .zip isnt included
10
+ $backup_filename = rtrim($_REQUEST['backup_name'], '.zip');
11
+
12
+ //Add zip
13
+ $backup_filename = $backup_filename. '.zip';
14
+ $backup_path = WPBACKITUP__BACKUP_PATH .'/' .$backup_filename ;
15
+
16
+ if(file_exists($backup_path) ) {
17
+
18
+ header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
19
+ header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
20
+
21
+ header('Content-type: application/zip');
22
+ header("Content-Disposition: attachment; filename=$backup_filename");
23
+ header("Content-Length: ".filesize($backup_path));
24
+ ob_get_clean();
25
+ readfile($backup_path);
26
+ if (ob_get_level()>1) ob_end_flush();
27
+ die();
28
+ }
29
+ }
30
+ }
31
+
32
+ //Return empty file
33
+ header ('Content-type: octet/stream');
34
+ header("Content-Disposition: attachment; filename=nobackup.log");
35
+ header("Content-Length: ' .100");
36
+ ob_get_clean();
37
+ echo('No backup found.'. PHP_EOL);
38
+ //echo($_REQUEST['_wpnonce']. PHP_EOL);
39
+ //echo($_REQUEST['viewlog_log']. PHP_EOL);
40
+ if (ob_get_level()>1) ob_end_flush();
41
+
42
+
43
+
44
+
45
+
46
+
47
+
48
+
lib/includes/job_backup.php CHANGED
@@ -585,6 +585,22 @@ function end_backup($err=null, $success=null){
585
  global $WPBackitup,$wp_backup, $logger, $backup_job;
586
  $logger->log_info(__METHOD__,"Begin");
587
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
588
  WPBackItUp_Backup::end(); //Release the lock
589
  $current_datetime = current_time( 'timestamp' );
590
  $WPBackitup->set_backup_lastrun_date($current_datetime);
@@ -597,13 +613,15 @@ function end_backup($err=null, $success=null){
597
 
598
  $logger->log('Script Processing Time:' .$processing_minutes .' Minutes ' .$processing_seconds .' Seconds');
599
 
600
- //Send Notification email
601
- send_backup_notification_email($err, $success);
602
-
603
-
604
  if (true===$success) $logger->log("Backup completed: SUCCESS");
605
  if (false===$success) $logger->log("Backup completed: ERROR");
606
- $logger->log("*** END BACKUP ***");
 
 
 
 
 
 
607
 
608
  $logFileName = $logger->logFileName;
609
  $logFilePath = $logger->logFilePath;
@@ -620,7 +638,7 @@ function end_backup($err=null, $success=null){
620
  exit(0);
621
  }
622
 
623
- function send_backup_notification_email($err, $success) {
624
  global $WPBackitup, $wp_backup, $logger,$status_array,$backup_job;
625
  $logger->log_info(__METHOD__,"Begin");
626
 
@@ -647,6 +665,11 @@ function send_backup_notification_email($err, $success) {
647
 
648
  if($success)
649
  {
 
 
 
 
 
650
  $subject = get_bloginfo() . ' - Backup completed successfully.';
651
  $message = '<b>Your backup completed successfully.</b><br/><br/>';
652
 
@@ -663,8 +686,6 @@ function send_backup_notification_email($err, $success) {
663
 
664
  $message .= 'Completion Code: ' . $backup_job->backup_id .'-'. $processing_minutes .'-' .$processing_seconds .'<br/>';
665
  $message .= 'WP BackItUp Version: ' . WPBACKITUP__VERSION . '<br/>';
666
-
667
-
668
  $message .= '<br/>';
669
 
670
 
@@ -693,9 +714,10 @@ function send_backup_notification_email($err, $success) {
693
  if(!$success)$term='error';
694
  $message .='<br/><br/>Checkout '. $WPBackitup->get_anchor_with_utm('www.wpbackitup.com', '', 'notification+email', $term) .' for info about WP BackItUp and our other products.<br/>';
695
 
 
696
  $notification_email = $WPBackitup->get_option('notification_email');
697
  if($notification_email)
698
- $utility->send_email($notification_email,$subject,$message);
699
 
700
  $logger->log_info(__function__,"End");
701
  }
@@ -825,14 +847,11 @@ function write_response_file_success() {
825
  $jsonResponse = new stdClass();
826
  $jsonResponse->backupStatus = 'success';
827
  $jsonResponse->backupMessage = 'success';
828
- $jsonResponse->backupFile = $wp_backup->backup_filename;
829
- $jsonResponse->backupZipLink = WPBACKITUP__BACKUP_URL . '/' . $wp_backup->backup_filename;
830
  $jsonResponse->backupLicense = $WPBackitup->license_active();
831
  $jsonResponse->backupRetained = $wp_backup->backup_retained_number;
832
 
833
- if (file_exists($logger->logFilePath)) {
834
- $jsonResponse->backupLogLink = basename($logger->logFileName,'.log');
835
- }
836
 
837
  write_response_file($jsonResponse);
838
  }
585
  global $WPBackitup,$wp_backup, $logger, $backup_job;
586
  $logger->log_info(__METHOD__,"Begin");
587
 
588
+ $logger->log('Zip up all the logs.');
589
+ //Zip up all the logs in the log folder
590
+ $logs_path = WPBACKITUP__PLUGIN_PATH .'logs';
591
+ $zip_file_path = $logs_path . '/logs_' .$backup_job->backup_id . '.zip';
592
+
593
+ //copy/replsce WP debug file
594
+ $wpdebug_file_path = WPBACKITUP__CONTENT_PATH . '/debug.log';
595
+ $logger->log_info(__METHOD__,"Copy WP Debug: " .$wpdebug_file_path);
596
+ if (file_exists($wpdebug_file_path)) {
597
+ copy( $wpdebug_file_path, $logs_path .'/wpdebug.log' );
598
+ }
599
+
600
+ $zip = new WPBackItUp_Zip($logger,$zip_file_path);
601
+ $zip->zip_files_in_folder($logs_path,$backup_job->backup_id,'*.log');
602
+ $zip->close();
603
+
604
  WPBackItUp_Backup::end(); //Release the lock
605
  $current_datetime = current_time( 'timestamp' );
606
  $WPBackitup->set_backup_lastrun_date($current_datetime);
613
 
614
  $logger->log('Script Processing Time:' .$processing_minutes .' Minutes ' .$processing_seconds .' Seconds');
615
 
 
 
 
 
616
  if (true===$success) $logger->log("Backup completed: SUCCESS");
617
  if (false===$success) $logger->log("Backup completed: ERROR");
618
+
619
+ $logger->log("*** END BACKUP ***");
620
+
621
+ //Send Notification email
622
+ $logger->log('Send Email notification');
623
+ $logs_attachment = array( $zip_file_path );
624
+ send_backup_notification_email($err, $success,$logs_attachment);
625
 
626
  $logFileName = $logger->logFileName;
627
  $logFilePath = $logger->logFilePath;
638
  exit(0);
639
  }
640
 
641
+ function send_backup_notification_email($err, $success,$logs=array()) {
642
  global $WPBackitup, $wp_backup, $logger,$status_array,$backup_job;
643
  $logger->log_info(__METHOD__,"Begin");
644
 
665
 
666
  if($success)
667
  {
668
+ //Don't send logs on success unless debug is on.
669
+ if (WPBACKITUP__DEBUG!==true){
670
+ $logs=array();
671
+ }
672
+
673
  $subject = get_bloginfo() . ' - Backup completed successfully.';
674
  $message = '<b>Your backup completed successfully.</b><br/><br/>';
675
 
686
 
687
  $message .= 'Completion Code: ' . $backup_job->backup_id .'-'. $processing_minutes .'-' .$processing_seconds .'<br/>';
688
  $message .= 'WP BackItUp Version: ' . WPBACKITUP__VERSION . '<br/>';
 
 
689
  $message .= '<br/>';
690
 
691
 
714
  if(!$success)$term='error';
715
  $message .='<br/><br/>Checkout '. $WPBackitup->get_anchor_with_utm('www.wpbackitup.com', '', 'notification+email', $term) .' for info about WP BackItUp and our other products.<br/>';
716
 
717
+
718
  $notification_email = $WPBackitup->get_option('notification_email');
719
  if($notification_email)
720
+ $utility->send_email($notification_email,$subject,$message,$logs);
721
 
722
  $logger->log_info(__function__,"End");
723
  }
847
  $jsonResponse = new stdClass();
848
  $jsonResponse->backupStatus = 'success';
849
  $jsonResponse->backupMessage = 'success';
850
+ $jsonResponse->backupFile = basename($wp_backup->backup_filename,'.zip');
 
851
  $jsonResponse->backupLicense = $WPBackitup->license_active();
852
  $jsonResponse->backupRetained = $wp_backup->backup_retained_number;
853
 
854
+ $jsonResponse->logFileExists = file_exists($logger->logFilePath);
 
 
855
 
856
  write_response_file($jsonResponse);
857
  }
lib/includes/job_cleanup.php CHANGED
@@ -155,6 +155,23 @@ if ('scheduled_cleanup'==$current_task) {
155
  $wp_backup->purge_old_files();
156
  $logger->log( '**END PURGE OLD FILES**' );
157
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
158
  $backup_job->set_task_complete();
159
 
160
  }
155
  $wp_backup->purge_old_files();
156
  $logger->log( '**END PURGE OLD FILES**' );
157
 
158
+ $logger->log( '**SECURE FOLDERS**' );
159
+ //Make sure backup folder is secured
160
+ $file_system = new WPBackItUp_FileSystem();
161
+
162
+ //Make sure backup folder is secured
163
+ $backup_dir = WPBACKITUP__CONTENT_PATH . '/' . WPBACKITUP__BACKUP_FOLDER;
164
+ $file_system->secure_folder( $backup_dir);
165
+
166
+ //--Check restore folder folders
167
+ $restore_dir = WPBACKITUP__CONTENT_PATH . '/' . WPBACKITUP__RESTORE_FOLDER;
168
+ $file_system->secure_folder( $restore_dir);
169
+
170
+ //Make sure logs folder is secured
171
+ $logs_dir = WPBACKITUP__PLUGIN_PATH .'/logs/';
172
+ $file_system->secure_folder( $logs_dir);
173
+ $logger->log( '**END SECURE FOLDERS**' );
174
+
175
  $backup_job->set_task_complete();
176
 
177
  }
lib/includes/job_restore.php CHANGED
@@ -375,12 +375,12 @@ function create_restore_folder($path) {
375
  die();
376
  }
377
 
378
- //create index.html
379
- $restore_index = $path .'/index.html';
380
- if( !is_file($restore_index) ) {
381
- $dfh = fopen( $restore_index, 'a' );
382
- fclose( $dfh );
383
- }
384
 
385
  $logger->log('Restore folder created:' .$path);
386
  }
375
  die();
376
  }
377
 
378
+ //Secure restore folder
379
+ $fileSystem->secure_folder( $path);
380
+
381
+ //Check logs folder too
382
+ $logs_dir = WPBACKITUP__PLUGIN_PATH .'/logs/';
383
+ $fileSystem->secure_folder( $logs_dir);
384
 
385
  $logger->log('Restore folder created:' .$path);
386
  }
lib/includes/listlogs.php CHANGED
@@ -1,13 +1,11 @@
1
- <?php
 
2
  //http://localhost/wp-390/wp-admin/admin-post.php?action=listlogs
3
  //http://localhost/wp-390/wp-admin/admin-post.php?action=listlogs&log=test
4
 
5
  $backup_folder_root = WPBACKITUP__BACKUP_PATH .'/';
6
  $plugin_log_folder = WPBACKITUP__PLUGIN_PATH .'/logs/';
7
 
8
- ?>
9
- <?php
10
-
11
  //List the log files
12
  if (!isset($_REQUEST['viewlog_log']) && empty($_REQUEST['log']) ){
13
 
1
+ <?php if (!defined ('ABSPATH')) die('No direct access allowed.');
2
+
3
  //http://localhost/wp-390/wp-admin/admin-post.php?action=listlogs
4
  //http://localhost/wp-390/wp-admin/admin-post.php?action=listlogs&log=test
5
 
6
  $backup_folder_root = WPBACKITUP__BACKUP_PATH .'/';
7
  $plugin_log_folder = WPBACKITUP__PLUGIN_PATH .'/logs/';
8
 
 
 
 
9
  //List the log files
10
  if (!isset($_REQUEST['viewlog_log']) && empty($_REQUEST['log']) ){
11
 
readme.txt CHANGED
@@ -1,10 +1,10 @@
1
  === WP Backitup ===
2
  Contributors: cssimmon,jcpeden
3
  Donate link: http://www.wpbackitup.com
4
- Tags: backup, back up, backups, backup wordpress, backup database, backup plugin, backup and restore, database, database backup, database restore, db, db backup, db restore, download database, full backup, mysql backup, restore, restore database,restore wordpress, restore wordpress backup,restoring wordpress, website backup, wordpress backup, wordpress restore, plugin, backup buddy
5
  Requires at least: 3.8.0
6
- Tested up to: 4.0
7
- Stable tag: 1.9
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -151,6 +151,13 @@ Our online documentation and full list of FAQs can be found at [www.wpbackitup.c
151
 
152
 
153
  == Changelog ==
 
 
 
 
 
 
 
154
  = 1.9.1 =
155
  * New Features: Long running backups are now supported.
156
  * Update: Extensive Performance improvements
1
  === WP Backitup ===
2
  Contributors: cssimmon,jcpeden
3
  Donate link: http://www.wpbackitup.com
4
+ Tags:backup,back up,backups,backup wordpress,backup database,backup plugin,backup and restore,database backup,database restore,db backup,db restore,download database,full backup,restore,restore database,restore wordpress,restore wordpress backup,restoring wordpress,website backup,wordpress backup,wordpress restore
5
  Requires at least: 3.8.0
6
+ Tested up to: 4.1
7
+ Stable tag: 1.9.2
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
151
 
152
 
153
  == Changelog ==
154
+ = 1.9.2 =
155
+ * New Features: Added WordPress 4.0.1 support
156
+ * New Features: Major Security Enhancements
157
+ * New Features: Added log attachment to backup notification email
158
+ * Update: Moved zip threshold to constant.
159
+ * Update: Added additional logging to archive process
160
+
161
  = 1.9.1 =
162
  * New Features: Long running backups are now supported.
163
  * Update: Extensive Performance improvements
views/backup.php CHANGED
@@ -138,6 +138,12 @@ if (!$backup_folder_exists) {
138
  <?php wp_nonce_field($this->namespace . "-viewlog"); ?>
139
  </form>
140
 
 
 
 
 
 
 
141
  <table class="widefat" id="datatable">
142
  <?php
143
 
@@ -188,7 +194,9 @@ if (!$backup_folder_exists) {
188
  <td><?php echo $file_datetime ?></td>
189
 
190
  <?php if ($zip_exists) :?>
191
- <td><a href="<?php echo WPBACKITUP__BACKUP_URL ?>/<?php echo $filename; ?>">Download</a></td>
 
 
192
  <?php else: ?>
193
  <td>&nbsp;</td>
194
  <?php endif; ?>
138
  <?php wp_nonce_field($this->namespace . "-viewlog"); ?>
139
  </form>
140
 
141
+ <form id = "download_backup" name = "download_backup" action="admin-post.php" method="post">
142
+ <input type="hidden" name="action" value="download_backup">
143
+ <input type="hidden" id="backup_name" name="backup_name" value="test">
144
+ <?php wp_nonce_field($this->namespace . "-download_backup"); ?>
145
+ </form>
146
+
147
  <table class="widefat" id="datatable">
148
  <?php
149
 
194
  <td><?php echo $file_datetime ?></td>
195
 
196
  <?php if ($zip_exists) :?>
197
+ <td><a class='downloadbackuplink' href="<?php echo basename($filename, ".zip") ?>">Download</a>
198
+ <!--<a href="<?php echo WPBACKITUP__BACKUP_URL ?>/<?php echo $filename; ?>">Download</a>-->
199
+ </td>
200
  <?php else: ?>
201
  <td>&nbsp;</td>
202
  <?php endif; ?>
views/restore.php CHANGED
@@ -76,7 +76,7 @@ if (!$restore_folder_exists) {
76
  ?>
77
  <tr <?php echo $class ?> id="row<?php echo $i; ?>">
78
  <td><?php echo $filename ?></td>
79
- <td><a href="<?php echo WPBACKITUP__BACKUP_URL ?>/<?php echo $filename; ?>">Download</a></td>
80
  <td><a href="#" title="<?php echo $filename; ?>" class="deleteRow" id="deleteRow<?php echo $i; ?>">Delete</a></td>
81
  <?php
82
  if ($this->license_active())
76
  ?>
77
  <tr <?php echo $class ?> id="row<?php echo $i; ?>">
78
  <td><?php echo $filename ?></td>
79
+ <td>&nbsp;</td>
80
  <td><a href="#" title="<?php echo $filename; ?>" class="deleteRow" id="deleteRow<?php echo $i; ?>">Delete</a></td>
81
  <?php
82
  if ($this->license_active())
wp-backitup.php CHANGED
@@ -12,7 +12,7 @@
12
  Plugin Name: WP Backitup
13
  Plugin URI: http://www.wpbackitup.com
14
  Description: Backup your content, settings, themes, plugins and media in just a few simple clicks.
15
- Version: 1.9.1
16
  Author: Chris Simmons
17
  Author URI: http://www.wpbackitup.com
18
  License: GPL3
@@ -34,7 +34,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
34
  */
35
 
36
  define( 'WPBACKITUP__NAMESPACE', 'wp-backitup' );
37
- define( 'WPBACKITUP__VERSION', '1.9.1');
38
  define( 'WPBACKITUP__DEBUG', false );
39
  define( 'WPBACKITUP__MINIMUM_WP_VERSION', '3.0' );
40
  define( 'WPBACKITUP__ITEM_NAME', 'WP Backitup' );
@@ -68,6 +68,8 @@ define( 'WPBACKITUP__SCRIPT_TIMEOUT_SECONDS', 900);//900 = 15 minutes
68
 
69
  define( 'WPBACKITUP__BACKUP_RETAINED_DAYS', 5);//5 days
70
 
 
 
71
  register_activation_hook( __FILE__, array( 'WPBackitup_Admin', 'activate' ) );
72
  register_deactivation_hook( __FILE__, array( 'WPBackitup_Admin', 'deactivate' ) );
73
 
@@ -114,8 +116,15 @@ function wpbackitup_custom_post_status(){
114
  }
115
  add_action( 'init', 'wpbackitup_custom_post_status' );
116
 
117
- // The checks here before loading are for performance only - unless one of those conditions is met, then none of the hooks will ever be used
118
- if (!is_admin() && (!defined('DOING_CRON') || !DOING_CRON) && (!defined('XMLRPC_REQUEST') || !XMLRPC_REQUEST) && empty($_SERVER['SHELL']) && empty($_SERVER['USER'])) return;
 
 
 
 
 
 
 
119
 
120
  require_once( WPBACKITUP__PLUGIN_PATH .'/lib/includes/class-wpbackitup-admin.php' );
121
  require_once( WPBACKITUP__PLUGIN_PATH .'/lib/includes/class-logger.php' );
12
  Plugin Name: WP Backitup
13
  Plugin URI: http://www.wpbackitup.com
14
  Description: Backup your content, settings, themes, plugins and media in just a few simple clicks.
15
+ Version: 1.9.2
16
  Author: Chris Simmons
17
  Author URI: http://www.wpbackitup.com
18
  License: GPL3
34
  */
35
 
36
  define( 'WPBACKITUP__NAMESPACE', 'wp-backitup' );
37
+ define( 'WPBACKITUP__VERSION', '1.9.2');
38
  define( 'WPBACKITUP__DEBUG', false );
39
  define( 'WPBACKITUP__MINIMUM_WP_VERSION', '3.0' );
40
  define( 'WPBACKITUP__ITEM_NAME', 'WP Backitup' );
68
 
69
  define( 'WPBACKITUP__BACKUP_RETAINED_DAYS', 5);//5 days
70
 
71
+ define( 'WPBACKITUP__ZIP_MAX_FILE_COUNT', 1000);
72
+
73
  register_activation_hook( __FILE__, array( 'WPBackitup_Admin', 'activate' ) );
74
  register_deactivation_hook( __FILE__, array( 'WPBackitup_Admin', 'deactivate' ) );
75
 
116
  }
117
  add_action( 'init', 'wpbackitup_custom_post_status' );
118
 
119
+ // Admin class will not be instantiate if any of these conditions are met
120
+ if (!is_admin()
121
+ && (!defined('DOING_CRON') || !DOING_CRON)
122
+ && (!defined('XMLRPC_REQUEST') || !XMLRPC_REQUEST)
123
+ && empty($_SERVER['SHELL'])
124
+ && empty($_SERVER['USER'])) {
125
+
126
+ return; //END HERE
127
+ }
128
 
129
  require_once( WPBACKITUP__PLUGIN_PATH .'/lib/includes/class-wpbackitup-admin.php' );
130
  require_once( WPBACKITUP__PLUGIN_PATH .'/lib/includes/class-logger.php' );