diff --git a/class/class-mainwp-child-back-up-buddy.php b/class/class-mainwp-child-back-up-buddy.php index 7d2d2cd..6974fa6 100644 --- a/class/class-mainwp-child-back-up-buddy.php +++ b/class/class-mainwp-child-back-up-buddy.php @@ -4,7 +4,7 @@ class MainWP_Child_Back_Up_Buddy { public static $instance = null; public $plugin_translate = 'mainwp-child'; public $is_backupbuddy_installed = false; - + static function Instance() { if ( null === MainWP_Child_Back_Up_Buddy::$instance ) { MainWP_Child_Back_Up_Buddy::$instance = new MainWP_Child_Back_Up_Buddy(); @@ -13,30 +13,30 @@ class MainWP_Child_Back_Up_Buddy { } public function __construct() { - if ( is_plugin_active( 'backupbuddy/backupbuddy.php' )) { - $this->is_backupbuddy_installed = true; + if ( is_plugin_active( 'backupbuddy/backupbuddy.php' )) { + $this->is_backupbuddy_installed = true; } - - if (!$this->is_backupbuddy_installed) { - return; - } - - if ( get_option( 'mainwp_backupbuddy_ext_enabled' ) !== 'Y' ) { - return; + + if (!$this->is_backupbuddy_installed) { + return; } - - add_action( 'wp_ajax_mainwp_backupbuddy_download_archive', array( $this, 'download_archive' ) ); - - add_action( 'mainwp_child_site_stats', array( $this, 'do_site_stats' ) ); - add_action( 'mainwp_extensions_reports_backups', array( $this, 'do_reports_backups' ) ); + + if ( get_option( 'mainwp_backupbuddy_ext_enabled' ) !== 'Y' ) { + return; + } + + add_action( 'wp_ajax_mainwp_backupbuddy_download_archive', array( $this, 'download_archive' ) ); + + add_action( 'mainwp_child_site_stats', array( $this, 'do_site_stats' ) ); + add_action( 'mainwp_extensions_reports_backups', array( $this, 'do_reports_backups' ) ); if ( get_option( 'mainwp_backupbuddy_hide_plugin' ) === 'hide' ) { - add_filter( 'all_plugins', array( $this, 'all_plugins' ) ); - add_action( 'admin_menu', array( $this, 'admin_menu' ) ); - add_filter( 'site_transient_update_plugins', array( &$this, 'remove_update_nag' ) ); + add_filter( 'all_plugins', array( $this, 'all_plugins' ) ); + add_action( 'admin_menu', array( $this, 'admin_menu' ) ); + add_filter( 'site_transient_update_plugins', array( &$this, 'remove_update_nag' ) ); } } - + function remove_update_nag( $value ) { if ( isset( $_POST['mainwpsignature'] ) ) { return $value; @@ -47,8 +47,8 @@ class MainWP_Child_Back_Up_Buddy { return $value; } - - + + public function all_plugins( $plugins ) { foreach ( $plugins as $key => $value ) { @@ -62,42 +62,42 @@ class MainWP_Child_Back_Up_Buddy { } public function admin_menu() { - global $submenu; + global $submenu; remove_menu_page( 'pb_backupbuddy_backup' ); - + if ( false !== stripos( $_SERVER['REQUEST_URI'], 'admin.php?page=pb_backupbuddy_' ) ) { wp_redirect( get_option( 'siteurl' ) . '/wp-admin/index.php' ); exit(); } } - - function do_site_stats() { - do_action( 'mainwp_client_reports_backups', 'backupbuddy'); + + function do_site_stats() { + do_action( 'mainwp_client_reports_backups', 'backupbuddy'); } - - function do_reports_backups($ext = '') { - if ($ext !== 'backupbuddy') - return; - - $backups = array(); + + function do_reports_backups($ext = '') { + if ($ext !== 'backupbuddy') + return; + + $backups = array(); $backup_sort_dates = array(); - + $files = glob( backupbuddy_core::getBackupDirectory() . 'backup*.zip' ); if ( ! is_array( $files ) ) { $files = array(); } - + $files2 = glob( backupbuddy_core::getBackupDirectory() . 'snapshot*.zip' ); if ( ! is_array( $files2 ) ) { $files2 = array(); } - + $files = array_merge( $files, $files2 ); - + if ( is_array( $files ) && !empty( $files ) ) { // For robustness. Without open_basedir the glob() function returns an empty array for no match. With open_basedir in effect the glob() function returns a boolean false for no match. - foreach( $files as $file_id => $file ) { - $serial = backupbuddy_core::get_serial_from_file( $file ); + foreach( $files as $file_id => $file ) { + $serial = backupbuddy_core::get_serial_from_file( $file ); $options = array(); if ( file_exists( backupbuddy_core::getLogDirectory() . 'fileoptions/' . $serial . '.txt' ) ) { require_once( pb_backupbuddy::plugin_path() . '/classes/fileoptions.php' ); @@ -107,7 +107,7 @@ class MainWP_Child_Back_Up_Buddy { $backup_options = ''; } $backup_integrity = backupbuddy_core::backup_integrity_check( $file, $backup_options, $options ); - + // Backup type. $pretty_type = array( 'full' => 'Full', @@ -116,55 +116,55 @@ class MainWP_Child_Back_Up_Buddy { 'themes' => 'Themes', 'plugins' => 'Plugins', ); - - + + // Defaults... $detected_type = ''; $file_size = ''; $modified = ''; $modified_time = 0; $integrity = ''; - + $main_string = 'Warn#284.'; - if ( is_array( $backup_integrity ) ) { + if ( is_array( $backup_integrity ) ) { // Calculate time ago. $time_ago = ''; if ( isset( $backup_integrity['modified'] ) ) { $time_ago = pb_backupbuddy::$format->time_ago( $backup_integrity['modified'] ) . ' ago'; } - + $detected_type = pb_backupbuddy::$format->prettify( $backup_integrity['detected_type'], $pretty_type ); if ( $detected_type == '' ) { - $detected_type = backupbuddy_core::pretty_backup_type( backupbuddy_core::getBackupTypeFromFile( $file ) ); + $detected_type = backupbuddy_core::pretty_backup_type( backupbuddy_core::getBackupTypeFromFile( $file ) ); } - - $modified_time = $backup_integrity['modified']; - $message = 'BackupBuddy ' . $detected_type . ' finished'; - $backup_type = $detected_type; - if (!empty($modified_time)) - do_action( 'mainwp_reports_backupbuddy_backup', $message, $backup_type, $modified_time); - } - } - } - - } - + + $modified_time = $backup_integrity['modified']; + $message = 'BackupBuddy ' . $detected_type . ' finished'; + $backup_type = $detected_type; + if (!empty($modified_time)) + do_action( 'mainwp_reports_backupbuddy_backup', $message, $backup_type, $modified_time); + } + } + } + + } + public function action() { $information = array(); - if ( ! $this->is_backupbuddy_installed || !class_exists('pb_backupbuddy')) { + if ( ! $this->is_backupbuddy_installed || !class_exists('pb_backupbuddy')) { MainWP_Helper::write( array( 'error' => __( 'Please install the BackupBuddy plugin on the child site.', $this->plugin_translate ) ) ); } - + if (get_option( 'mainwp_backupbuddy_ext_enabled' ) !== 'Y') - MainWP_Helper::update_option( 'mainwp_backupbuddy_ext_enabled', 'Y' ); - + MainWP_Helper::update_option( 'mainwp_backupbuddy_ext_enabled', 'Y' ); + if ( ! class_exists( 'backupbuddy_core' ) ) { require_once( pb_backupbuddy::plugin_path() . '/classes/core.php' ); } - + if ( !isset( pb_backupbuddy::$options ) ) { pb_backupbuddy::load(); - } + } if ( isset( $_POST['mwp_action'] ) ) { switch ( $_POST['mwp_action'] ) { @@ -173,25 +173,25 @@ class MainWP_Child_Back_Up_Buddy { break; case 'save_settings': $information = $this->save_settings(); - break; + break; case 'reset_defaults': $information = $this->reset_defaults(); break; case 'get_notifications': $information = $this->get_notifications(); - break; - case 'schedules_list': - $information = $this->schedules_list(); - break; - case 'run_scheduled_backup': - $information = $this->run_scheduled_backup(); - break; + break; + case 'schedules_list': + $information = $this->schedules_list(); + break; + case 'run_scheduled_backup': + $information = $this->run_scheduled_backup(); + break; case 'save_scheduled_backup': $information = $this->save_scheduled_backup(); break; case 'delete_scheduled_backup': $information = $this->delete_scheduled_backup(); - break; + break; case 'save_profile': $information = $this->save_profile(); break; @@ -209,7 +209,7 @@ class MainWP_Child_Back_Up_Buddy { break; case 'get_hash': $information = $this->get_hash(); - break; + break; case 'zip_viewer': $information = $this->zip_viewer(); break; @@ -221,107 +221,110 @@ class MainWP_Child_Back_Up_Buddy { break; case 'view_log': $information = $this->view_log(); - break; + break; case 'view_detail': $information = $this->view_detail(); break; case 'reset_integrity': $information = $this->reset_integrity(); break; - case 'download_archive': - $information = $this->download_archive(); - break; - case 'create_backup': - $information = $this->create_backup(); - break; - case 'start_backup': - $information = $this->start_backup(); - break; - case 'backup_status': - $information = $this->backup_status(); - break; - case 'stop_backup': - $information = $this->stop_backup(); - break; - case 'remote_save': - $information = $this->remote_save(); - break; - case 'remote_delete': - $information = $this->remote_delete(); - break; - case 'remote_send': - $information = $this->remote_send(); - break; - case 'get_main_log': - $information = $this->get_main_log(); - break; - case 'settings_other': - $information = $this->settings_other(); - break; - case 'malware_scan': - $information = $this->malware_scan(); - break; - case 'live_setup': - $information = $this->live_setup(); - break; - case 'live_save_settings': - $information = $this->live_save_settings(); - break; - case 'live_action_disconnect': - $information = $this->live_action_disconnect(); - break; - case 'live_action': - $information = $this->live_action(); - break; - case 'download_troubleshooting': - $information = $this->download_troubleshooting(); - break; - case 'get_live_backups': - $information = $this->get_live_backups(); - break; - case 'copy_file_to_local': - $information = $this->copy_file_to_local(); - break; - case 'delete_file_backup': - $information = $this->delete_file_backup(); - break; - case 'get_live_stats': - $information = $this->get_live_stats(); - break; - case 'load_products_license': - $information = $this->load_products_license(); - break; - case 'save_license_settings': - $information = $this->save_license_settings(); - break; - case 'activate_package': - $information = $this->activate_package(); - break; - case 'deactivate_package': - $information = $this->deactivate_package(); - break; + case 'download_archive': + $information = $this->download_archive(); + break; + case 'create_backup': + $information = $this->create_backup(); + break; + case 'start_backup': + $information = $this->start_backup(); + break; + case 'backup_status': + $information = $this->backup_status(); + break; + case 'stop_backup': + $information = $this->stop_backup(); + break; + case 'remote_save': + $information = $this->remote_save(); + break; + case 'remote_delete': + $information = $this->remote_delete(); + break; + case 'remote_send': + $information = $this->remote_send(); + break; + case 'remote_list': + $information = $this->remote_list(); + break; + case 'get_main_log': + $information = $this->get_main_log(); + break; + case 'settings_other': + $information = $this->settings_other(); + break; + case 'malware_scan': + $information = $this->malware_scan(); + break; + case 'live_setup': + $information = $this->live_setup(); + break; + case 'live_save_settings': + $information = $this->live_save_settings(); + break; + case 'live_action_disconnect': + $information = $this->live_action_disconnect(); + break; + case 'live_action': + $information = $this->live_action(); + break; + case 'download_troubleshooting': + $information = $this->download_troubleshooting(); + break; + case 'get_live_backups': + $information = $this->get_live_backups(); + break; + case 'copy_file_to_local': + $information = $this->copy_file_to_local(); + break; + case 'delete_file_backup': + $information = $this->delete_file_backup(); + break; + case 'get_live_stats': + $information = $this->get_live_stats(); + break; + case 'load_products_license': + $information = $this->load_products_license(); + break; + case 'save_license_settings': + $information = $this->save_license_settings(); + break; + case 'activate_package': + $information = $this->activate_package(); + break; + case 'deactivate_package': + $information = $this->deactivate_package(); + break; } } MainWP_Helper::write( $information ); } - function set_showhide() { + function set_showhide() { $hide = isset( $_POST['showhide'] ) && ( 'hide' === $_POST['showhide'] ) ? 'hide' : ''; MainWP_Helper::update_option( 'mainwp_backupbuddy_hide_plugin', $hide ); $information['result'] = 'SUCCESS'; return $information; } - + function save_settings() { - + $type = isset($_POST['type']) ? $_POST['type'] : ''; - + if ($type !== 'general_settings' && $type !== 'advanced_settings' && $type !== 'all' ) { return array('error' => __('Invalid data!'), 'extra' => 'Invalid settings data!'); } - - $filter_advanced_settings = array( + + $filter_advanced_settings = array( 'backup_reminders', 'archive_name_format', 'archive_name_profile', @@ -332,16 +335,16 @@ class MainWP_Child_Back_Up_Buddy { 'limit_single_cron_per_pass', 'use_internal_cron', 'remote_send_timeout_retries', - 'hide_live', + 'hide_live', 'set_greedy_execution_time', 'archive_limit_size_big', - 'max_execution_time', + 'max_execution_time', 'log_level', 'save_backup_sum_log', 'max_site_log_size', 'max_send_stats_days', 'max_send_stats_count', - 'max_notifications_age_days', + 'max_notifications_age_days', 'backup_mode', 'delete_archives_pre_backup', 'disable_https_local_ssl_verify', @@ -350,13 +353,13 @@ class MainWP_Child_Back_Up_Buddy { 'integrity_check', // profiles#0 'backup_cron_rescheduling', 'skip_spawn_cron_call', - 'backup_cron_passed_force_time', + 'backup_cron_passed_force_time', 'database_method_strategy', 'skip_database_dump', // profiles#0 'breakout_tables', 'force_single_db_file', 'phpmysqldump_maxrows', - 'ignore_command_length_check', + 'ignore_command_length_check', 'compression', 'zip_method_strategy', 'alternative_zip_2', @@ -369,11 +372,11 @@ class MainWP_Child_Back_Up_Buddy { 'ignore_zip_warnings', 'ignore_zip_symlinks', ); - - $filter_general_settings = array( + + $filter_general_settings = array( 'importbuddy_pass_hash', - 'importbuddy_pass_length', + 'importbuddy_pass_length', 'backup_directory', 'role_access', 'archive_limit_age', @@ -411,38 +414,38 @@ class MainWP_Child_Back_Up_Buddy { 'skip_database_dump', 'backup_nonwp_tables' ); - + $settings = unserialize(base64_decode($_POST['options'])); - + $save_settings = array(); - + if (is_array($settings)) { - if ($type === 'all' || 'general_settings' === $type) { - foreach($filter_general_settings as $field) { - if(isset($settings[$field])) { - $save_settings[$field] = $settings[$field]; + if ($type === 'all' || 'general_settings' === $type) { + foreach($filter_general_settings as $field) { + if(isset($settings[$field])) { + $save_settings[$field] = $settings[$field]; + } } } - } - - if ($type === 'all' || 'advanced_settings' === $type) { - foreach($filter_advanced_settings as $field) { - if(isset($settings[$field])) { - $save_settings[$field] = $settings[$field]; + + if ($type === 'all' || 'advanced_settings' === $type) { + foreach($filter_advanced_settings as $field) { + if(isset($settings[$field])) { + $save_settings[$field] = $settings[$field]; + } } } - } - } - + } + if (!empty($save_settings)) { $newOptions = pb_backupbuddy::$options; - + foreach($newOptions as $key => $val) { if (isset($save_settings[$key])) { $newOptions[$key] = $save_settings[$key]; } } - + if (isset($newOptions['profiles']) && isset($newOptions['profiles'][0])) { foreach ($filter_profile0_values as $field) { if (isset($settings[$field])) { @@ -450,27 +453,27 @@ class MainWP_Child_Back_Up_Buddy { } } } - - if ('general_settings' === $type || 'all' === $type ) { - $newOptions['importbuddy_pass_hash_confirm'] = ''; - } - + + if ('general_settings' === $type || 'all' === $type ) { + $newOptions['importbuddy_pass_hash_confirm'] = ''; + } + global $wpdb; $option = 'pb_' . pb_backupbuddy::settings( 'slug' ); $newOptions = sanitize_option( $option, $newOptions ); $newOptions = maybe_serialize( $newOptions ); - + add_site_option( $option, $newOptions, '', 'no'); // 'No' prevents autoload if we wont always need the data loaded. $wpdb->update( $wpdb->options, array( 'option_value' => $newOptions ), array( 'option_name' => $option ) ); - + $information['backupDirectoryDefault'] = backupbuddy_core::_getBackupDirectoryDefault(); $information['result'] = 'SUCCESS'; - } - + } + return $information; } - - function reset_defaults() { + + function reset_defaults() { // Keep log serial. $old_log_serial = pb_backupbuddy::$options['log_serial']; @@ -490,184 +493,184 @@ class MainWP_Child_Back_Up_Buddy { backupbuddy_core::verify_directories( $skipTempGeneration = true ); // Re-verify directories such as backup dir, temp, etc. $resetNote = __( 'Plugin settings have been reset to defaults.', 'mainwp-child' ); backupbuddy_core::addNotification( 'settings_reset', 'Plugin settings reset', $resetNote . $keepDestNote ); - + $information['message'] = $resetNote . $keepDestNote; $information['result'] = 'SUCCESS'; return $information; } - - function get_notifications() { - return array('result' => 'SUCCESS', 'notifications' => backupbuddy_core::getNotifications() ); + + function get_notifications() { + return array('result' => 'SUCCESS', 'notifications' => backupbuddy_core::getNotifications() ); } - - function get_schedules_run_time() { - $schedules_run_time = array(); - foreach ( pb_backupbuddy::$options['schedules'] as $schedule_id => $schedule ) { - // Determine first run. - $first_run = pb_backupbuddy::$format->date( pb_backupbuddy::$format->localize_time( $schedule['first_run'] ) ); - // Determine last run. - if ( isset( $schedule['last_run'] ) ) { // backward compatibility before last run tracking added. Pre v2.2.11. Eventually remove this. - if ( $schedule['last_run'] == 0 ) { - $last_run = '' . __( 'Never', 'it-l10n-backupbuddy' ) . ''; - } else { - $last_run = pb_backupbuddy::$format->date( pb_backupbuddy::$format->localize_time( $schedule['last_run'] ) ); - } - } else { // backward compatibility for before last run tracking was added. - $last_run = ' ' . __( 'Unknown', 'it-l10n-backupbuddy' ) . ''; - } - // Determine next run. - $next_run = wp_next_scheduled( 'backupbuddy_cron', array( 'run_scheduled_backup', array( (int)$schedule_id ) ) ); - if ( false === $next_run ) { - $next_run = 'Error: Cron event not found'; - } else { - $next_run = pb_backupbuddy::$format->date( pb_backupbuddy::$format->localize_time( $next_run ) ); - } + function get_schedules_run_time() { + $schedules_run_time = array(); + foreach ( pb_backupbuddy::$options['schedules'] as $schedule_id => $schedule ) { + // Determine first run. + $first_run = pb_backupbuddy::$format->date( pb_backupbuddy::$format->localize_time( $schedule['first_run'] ) ); + // Determine last run. + if ( isset( $schedule['last_run'] ) ) { // backward compatibility before last run tracking added. Pre v2.2.11. Eventually remove this. + if ( $schedule['last_run'] == 0 ) { + $last_run = '' . __( 'Never', 'it-l10n-backupbuddy' ) . ''; + } else { + $last_run = pb_backupbuddy::$format->date( pb_backupbuddy::$format->localize_time( $schedule['last_run'] ) ); + } + } else { // backward compatibility for before last run tracking was added. + $last_run = ' ' . __( 'Unknown', 'it-l10n-backupbuddy' ) . ''; + } - $run_time = 'First run: ' . $first_run . '
' . - 'Last run: ' . $last_run . '
' . - 'Next run: ' . $next_run; + // Determine next run. + $next_run = wp_next_scheduled( 'backupbuddy_cron', array( 'run_scheduled_backup', array( (int)$schedule_id ) ) ); + if ( false === $next_run ) { + $next_run = 'Error: Cron event not found'; + } else { + $next_run = pb_backupbuddy::$format->date( pb_backupbuddy::$format->localize_time( $next_run ) ); + } - $schedules_run_time[$schedule_id] = $run_time; + $run_time = 'First run: ' . $first_run . '
' . + 'Last run: ' . $last_run . '
' . + 'Next run: ' . $next_run; - } - - return $schedules_run_time; - } - - function schedules_list() { - $information = array(); + $schedules_run_time[$schedule_id] = $run_time; + + } + + return $schedules_run_time; + } + + function schedules_list() { + $information = array(); $information['schedules'] = pb_backupbuddy::$options['schedules']; - $information['next_schedule_index'] = pb_backupbuddy::$options['next_schedule_index']; - $information['schedules_run_time'] = $this->get_schedules_run_time(); + $information['next_schedule_index'] = pb_backupbuddy::$options['next_schedule_index']; + $information['schedules_run_time'] = $this->get_schedules_run_time(); $information['result'] = 'SUCCESS'; return $information; } - - + + function run_scheduled_backup() { if ( ! is_main_site() ) { // Only run for main site or standalone. Multisite subsites do not allow schedules. return array('error' => __('Only run for main site or standalone. Multisite subsites do not allow schedules', 'mainwp-child') ); } - + $schedule_id = (int) $_POST['schedule_id']; - + if ( !isset( pb_backupbuddy::$options['schedules'][$schedule_id] ) || ! is_array( pb_backupbuddy::$options['schedules'][$schedule_id] ) ) { return array('error' => __( 'Error: not found the backup schedule or invalid data', 'mainwp-child' )); } - + pb_backupbuddy::alert( 'Manually running scheduled backup "' . pb_backupbuddy::$options['schedules'][$schedule_id]['title'] . '" in the background.' . '
' . - __( 'Note: If there is no site activity there may be delays between steps in the backup. Access the site or use a 3rd party service, such as a free pinging service, to generate site activity.', 'it-l10n-backupbuddy' ) ); - pb_backupbuddy_cron::_run_scheduled_backup( $schedule_id ); - - $information['result'] = 'SUCCESS'; - + __( 'Note: If there is no site activity there may be delays between steps in the backup. Access the site or use a 3rd party service, such as a free pinging service, to generate site activity.', 'it-l10n-backupbuddy' ) ); + pb_backupbuddy_cron::_run_scheduled_backup( $schedule_id ); + + $information['result'] = 'SUCCESS'; + return $information; - } - - - function save_scheduled_backup() { + } + + + function save_scheduled_backup() { $schedule_id = intval($_POST['schedule_id']); $schedule = unserialize(base64_decode($_POST['data'])); - + if (!is_array($schedule)) { return array('error' => __( 'Invalid schedule data', 'mainwp-child' )); } - $information = array(); - // add new - if (!isset(pb_backupbuddy::$options['schedules'][$schedule_id])) { - $next_index = pb_backupbuddy::$options['next_schedule_index']; - pb_backupbuddy::$options['next_schedule_index']++; // This change will be saved in savesettings function below. - pb_backupbuddy::$options['schedules'][$schedule_id] = $schedule; - $result = backupbuddy_core::schedule_event( $schedule['first_run'], $schedule['interval'], 'run_scheduled_backup', array( $schedule_id ) ); - if ( $result === false ) { - return array('error' => 'Error scheduling event with WordPress. Your schedule may not work properly. Please try again. Error #3488439b. Check your BackupBuddy error log for details.'); - } - } else { - $first_run = $schedule['first_run']; - $next_scheduled_time = wp_next_scheduled( 'backupbuddy_cron', array( 'run_scheduled_backup', array( (int)$schedule_id ) ) ); - backupbuddy_core::unschedule_event( $next_scheduled_time, 'backupbuddy_cron', array( 'run_scheduled_backup', array( (int)$schedule_id ) ) ); - backupbuddy_core::schedule_event( $first_run, $schedule['interval'], 'run_scheduled_backup', array( (int)$schedule_id ) ); // Add new schedule. - pb_backupbuddy::$options['schedules'][$schedule_id] = $schedule; - } - pb_backupbuddy::save(); - $information['result'] = 'SUCCESS'; + $information = array(); + // add new + if (!isset(pb_backupbuddy::$options['schedules'][$schedule_id])) { + $next_index = pb_backupbuddy::$options['next_schedule_index']; + pb_backupbuddy::$options['next_schedule_index']++; // This change will be saved in savesettings function below. + pb_backupbuddy::$options['schedules'][$schedule_id] = $schedule; + $result = backupbuddy_core::schedule_event( $schedule['first_run'], $schedule['interval'], 'run_scheduled_backup', array( $schedule_id ) ); + if ( $result === false ) { + return array('error' => 'Error scheduling event with WordPress. Your schedule may not work properly. Please try again. Error #3488439b. Check your BackupBuddy error log for details.'); + } + } else { + $first_run = $schedule['first_run']; + $next_scheduled_time = wp_next_scheduled( 'backupbuddy_cron', array( 'run_scheduled_backup', array( (int)$schedule_id ) ) ); + backupbuddy_core::unschedule_event( $next_scheduled_time, 'backupbuddy_cron', array( 'run_scheduled_backup', array( (int)$schedule_id ) ) ); + backupbuddy_core::schedule_event( $first_run, $schedule['interval'], 'run_scheduled_backup', array( (int)$schedule_id ) ); // Add new schedule. + pb_backupbuddy::$options['schedules'][$schedule_id] = $schedule; + } + pb_backupbuddy::save(); + $information['result'] = 'SUCCESS'; $information['schedules'] = pb_backupbuddy::$options['schedules']; - $information['next_schedule_index'] = pb_backupbuddy::$options['next_schedule_index']; - $information['schedules_run_time'] = $this->get_schedules_run_time(); + $information['next_schedule_index'] = pb_backupbuddy::$options['next_schedule_index']; + $information['schedules_run_time'] = $this->get_schedules_run_time(); return $information; } - - - function save_profile() { + + + function save_profile() { $profile_id = $_POST['profile_id']; $profile = unserialize(base64_decode($_POST['data'])); - + if (!is_array($profile)) { return array('error' => __( 'Invalid profile data', 'mainwp-child' )); } - - pb_backupbuddy::$options['profiles'][$profile_id] = $profile; + + pb_backupbuddy::$options['profiles'][$profile_id] = $profile; pb_backupbuddy::save(); - $information['result'] = 'SUCCESS'; + $information['result'] = 'SUCCESS'; return $information; } - - - function delete_profile() { - $profile_id = $_POST['profile_id']; - + + + function delete_profile() { + $profile_id = $_POST['profile_id']; + if (isset(pb_backupbuddy::$options['profiles'][$profile_id])) - unset(pb_backupbuddy::$options['profiles'][$profile_id]); - - pb_backupbuddy::save(); - $information['result'] = 'SUCCESS'; + unset(pb_backupbuddy::$options['profiles'][$profile_id]); + + pb_backupbuddy::save(); + $information['result'] = 'SUCCESS'; return $information; } - - function delete_backup( $type = 'default', $subsite_mode = false ) { + + function delete_backup( $type = 'default', $subsite_mode = false ) { $item_ids = $_POST['item_ids']; - $item_ids = explode(',', $item_ids); + $item_ids = explode(',', $item_ids); $information = array(); if ( is_array( $item_ids ) && count( $item_ids ) > 0 ) { - $needs_save = false; - $deleted_files = array(); - foreach( $item_ids as $item ) { - if ( file_exists( backupbuddy_core::getBackupDirectory() . $item ) ) { - if ( @unlink( backupbuddy_core::getBackupDirectory() . $item ) === true ) { - $deleted_files[] = $item; - - // Cleanup any related fileoptions files. - $serial = backupbuddy_core::get_serial_from_file( $item ); + $needs_save = false; + $deleted_files = array(); + foreach( $item_ids as $item ) { + if ( file_exists( backupbuddy_core::getBackupDirectory() . $item ) ) { + if ( @unlink( backupbuddy_core::getBackupDirectory() . $item ) === true ) { + $deleted_files[] = $item; - $backup_files = glob( backupbuddy_core::getBackupDirectory() . '*.zip' ); - if ( ! is_array( $backup_files ) ) { - $backup_files = array(); + // Cleanup any related fileoptions files. + $serial = backupbuddy_core::get_serial_from_file( $item ); + + $backup_files = glob( backupbuddy_core::getBackupDirectory() . '*.zip' ); + if ( ! is_array( $backup_files ) ) { + $backup_files = array(); + } + if ( count( $backup_files ) > 5 ) { // Keep a minimum number of backups in array for stats. + $this_serial = backupbuddy_core::get_serial_from_file( $item ); + $fileoptions_file = backupbuddy_core::getLogDirectory() . 'fileoptions/' . $this_serial . '.txt'; + if ( file_exists( $fileoptions_file ) ) { + @unlink( $fileoptions_file ); } - if ( count( $backup_files ) > 5 ) { // Keep a minimum number of backups in array for stats. - $this_serial = backupbuddy_core::get_serial_from_file( $item ); - $fileoptions_file = backupbuddy_core::getLogDirectory() . 'fileoptions/' . $this_serial . '.txt'; - if ( file_exists( $fileoptions_file ) ) { - @unlink( $fileoptions_file ); - } - if ( file_exists( $fileoptions_file . '.lock' ) ) { - @unlink( $fileoptions_file . '.lock' ); - } - $needs_save = true; + if ( file_exists( $fileoptions_file . '.lock' ) ) { + @unlink( $fileoptions_file . '.lock' ); } - } - } // End if file exists. - } // End foreach. - if ( $needs_save === true ) { - pb_backupbuddy::save(); - } - - $information['result'] = 'SUCCESS'; - - } // End if deleting backup(s). - return $information; - } + $needs_save = true; + } + } + } // End if file exists. + } // End foreach. + if ( $needs_save === true ) { + pb_backupbuddy::save(); + } + + $information['result'] = 'SUCCESS'; + + } // End if deleting backup(s). + return $information; + } function backup_list() { require_once( pb_backupbuddy::plugin_path() . '/destinations/bootstrap.php' ); @@ -675,15 +678,15 @@ class MainWP_Child_Back_Up_Buddy { $information['backup_list'] = $this->get_backup_list(); $information['recent_backup_list'] = $this->get_recent_backup_list(); //$information['destinations_list'] = pb_backupbuddy_destinations::get_destinations_list(); - $backup_directory = backupbuddy_core::getBackupDirectory(); + $backup_directory = backupbuddy_core::getBackupDirectory(); $backup_directory = str_replace( '\\', '/', $backup_directory ); - $backup_directory = rtrim( $backup_directory, '/\\' ) . '/'; - $information['backupDirectoryWithinSiteRoot'] = (FALSE !== stristr( $backup_directory, ABSPATH )) ? 'yes' : 'no'; + $backup_directory = rtrim( $backup_directory, '/\\' ) . '/'; + $information['backupDirectoryWithinSiteRoot'] = (FALSE !== stristr( $backup_directory, ABSPATH )) ? 'yes' : 'no'; $information['result'] = 'SUCCESS'; return $information; } - - function save_note() { + + function save_note() { if ( !isset( pb_backupbuddy::$classes['zipbuddy'] ) ) { require_once( pb_backupbuddy::plugin_path() . '/lib/zipbuddy/zipbuddy.php' ); pb_backupbuddy::$classes['zipbuddy'] = new pluginbuddy_zipbuddy( backupbuddy_core::getBackupDirectory() ); @@ -703,9 +706,9 @@ class MainWP_Child_Back_Up_Buddy { //$new_comment = base64_encode( serialize( $comment ) ); $comment_result = pb_backupbuddy::$classes['zipbuddy']->set_comment( $backup_file, $comment ); - + $information = array(); - if ( $comment_result === true ) { + if ( $comment_result === true ) { $information['result'] = 'SUCCESS'; } @@ -718,17 +721,17 @@ class MainWP_Child_Back_Up_Buddy { if ( true === ( $result = $backup_options->is_ok() ) ) { $backup_options->options['integrity']['comment'] = $note; $backup_options->save(); - } + } return $information; - } - - function get_hash() { - $callback_data = $_POST['callback_data']; + } + + function get_hash() { + $callback_data = $_POST['callback_data']; $file = backupbuddy_core::getBackupDirectory() . $callback_data; if (file_exists($file)) - return array( 'result' =>'SUCCESS', 'hash' => md5_file( $file ) ); + return array( 'result' =>'SUCCESS', 'hash' => md5_file( $file ) ); else - return array( 'error' =>'Not found the file' ); + return array( 'error' =>'Not found the file' ); } function zip_viewer() { @@ -750,7 +753,7 @@ class MainWP_Child_Back_Up_Buddy { // Purge cache if too old. if ( file_exists( $fileoptions_file ) && ( ( time() - filemtime( $fileoptions_file ) ) > $max_cache_time ) ) { if ( false === unlink( $fileoptions_file ) ) { - $alerts[] = 'Error #456765545. Unable to wipe cached fileoptions file `' . $fileoptions_file . '`.' ; + $alerts[] = 'Error #456765545. Unable to wipe cached fileoptions file `' . $fileoptions_file . '`.' ; } } @@ -771,7 +774,7 @@ class MainWP_Child_Back_Up_Buddy { // Just make sure we have a sensible files listing if ( ! is_array( $files ) ) { - return array( 'error' => 'Error #548484. Unable to retrieve file listing from backup file `' . htmlentities( $zip_viewer ) . '`.' ); + return array( 'error' => 'Error #548484. Unable to retrieve file listing from backup file `' . htmlentities( $zip_viewer ) . '`.' ); } // To record subdirs of this root @@ -807,7 +810,7 @@ class MainWP_Child_Back_Up_Buddy { if ( 0 == strcmp( $file[ 0 ], $root ) ) { unset( $files[ $key ] ); - continue; + continue; } @@ -851,70 +854,70 @@ class MainWP_Child_Back_Up_Buddy { } } - + return array('result' => 'SUCCESS', 'files' => $files, 'message' => implode('
', $alerts)); } - + function restore_file_view() { - $archive_file = $_POST[ 'archive' ]; // archive to extract from. - $file = $_POST[ 'file' ]; // file to extract. - $serial = backupbuddy_core::get_serial_from_file( $archive_file ); // serial of archive. - $temp_file = uniqid(); // temp filename to extract into. + $archive_file = $_POST[ 'archive' ]; // archive to extract from. + $file = $_POST[ 'file' ]; // file to extract. + $serial = backupbuddy_core::get_serial_from_file( $archive_file ); // serial of archive. + $temp_file = uniqid(); // temp filename to extract into. - require_once( pb_backupbuddy::plugin_path() . '/lib/zipbuddy/zipbuddy.php' ); - $zipbuddy = new pluginbuddy_zipbuddy( backupbuddy_core::getBackupDirectory() ); + require_once( pb_backupbuddy::plugin_path() . '/lib/zipbuddy/zipbuddy.php' ); + $zipbuddy = new pluginbuddy_zipbuddy( backupbuddy_core::getBackupDirectory() ); - // Calculate temp directory & lock it down. - $temp_dir = get_temp_dir(); - $destination = $temp_dir . 'backupbuddy-' . $serial; - if ( ( ( ! file_exists( $destination ) ) && ( false === mkdir( $destination ) ) ) ) { - $error = 'Error #458485945b: Unable to create temporary location.'; - pb_backupbuddy::status( 'error', $error ); - return array('error' => $error); + // Calculate temp directory & lock it down. + $temp_dir = get_temp_dir(); + $destination = $temp_dir . 'backupbuddy-' . $serial; + if ( ( ( ! file_exists( $destination ) ) && ( false === mkdir( $destination ) ) ) ) { + $error = 'Error #458485945b: Unable to create temporary location.'; + pb_backupbuddy::status( 'error', $error ); + return array('error' => $error); + } + + // If temp directory is within webroot then lock it down. + $temp_dir = str_replace( '\\', '/', $temp_dir ); // Normalize for Windows. + $temp_dir = rtrim( $temp_dir, '/\\' ) . '/'; // Enforce single trailing slash. + if ( FALSE !== stristr( $temp_dir, ABSPATH ) ) { // Temp dir is within webroot. + pb_backupbuddy::anti_directory_browsing( $destination ); + } + unset( $temp_dir ); + + $message = 'Extracting "' . $file . '" from archive "' . $archive_file . '" into temporary file "' . $destination . '". '; + //echo ''; + $error = 'Error #584984458. Unable to extract.'; + pb_backupbuddy::status( 'error', $error ); + return array( 'error' => $error ); + } else { // success. + $file_content = file_get_contents( $destination . '/' . $temp_file ); + } + + // Try to cleanup. + if ( file_exists( $destination ) ) { + if ( false === pb_backupbuddy::$filesystem->unlink_recursive( $destination ) ) { + pb_backupbuddy::status( 'details', 'Unable to delete temporary holding directory `' . $destination . '`.' ); + } else { + pb_backupbuddy::status( 'details', 'Cleaned up temporary files.' ); } + } - // If temp directory is within webroot then lock it down. - $temp_dir = str_replace( '\\', '/', $temp_dir ); // Normalize for Windows. - $temp_dir = rtrim( $temp_dir, '/\\' ) . '/'; // Enforce single trailing slash. - if ( FALSE !== stristr( $temp_dir, ABSPATH ) ) { // Temp dir is within webroot. - pb_backupbuddy::anti_directory_browsing( $destination ); - } - unset( $temp_dir ); - - $message = 'Extracting "' . $file . '" from archive "' . $archive_file . '" into temporary file "' . $destination . '". '; - //echo ''; - $error = 'Error #584984458. Unable to extract.'; - pb_backupbuddy::status( 'error', $error ); - return array( 'error' => $error ); - } else { // success. - $file_content = file_get_contents( $destination . '/' . $temp_file ); - } - - // Try to cleanup. - if ( file_exists( $destination ) ) { - if ( false === pb_backupbuddy::$filesystem->unlink_recursive( $destination ) ) { - pb_backupbuddy::status( 'details', 'Unable to delete temporary holding directory `' . $destination . '`.' ); - } else { - pb_backupbuddy::status( 'details', 'Cleaned up temporary files.' ); - } - } - - return array( 'result' => 'SUCCESS', 'file_content' => $file_content ); + return array( 'result' => 'SUCCESS', 'file_content' => $file_content ); } - - - function restore_file_restore() { + + + function restore_file_restore() { $files = $_POST[ 'files' ]; // file to extract. $archive_file = $_POST[ 'archive' ]; // archive to extract from. @@ -935,49 +938,49 @@ class MainWP_Child_Back_Up_Buddy { $pb_backupbuddy_js_status = true; pb_backupbuddy::set_status_serial( 'restore' ); global $wp_version; - pb_backupbuddy::status( 'details', 'BackupBuddy v' . pb_backupbuddy::settings( 'version' ) . ' using WordPress v' . $wp_version . ' on ' . PHP_OS . '.' ); + pb_backupbuddy::status( 'details', 'BackupBuddy v' . pb_backupbuddy::settings( 'version' ) . ' using WordPress v' . $wp_version . ' on ' . PHP_OS . '.' ); - require( pb_backupbuddy::plugin_path() . '/classes/_restoreFiles.php' ); - - ob_start(); - $result = backupbuddy_restore_files::restore( backupbuddy_core::getBackupDirectory() . $archive_file, $files, $finalPath = ABSPATH ); - $restore_result = ob_get_clean(); - pb_backupbuddy::flush(); + require( pb_backupbuddy::plugin_path() . '/classes/_restoreFiles.php' ); + + ob_start(); + $result = backupbuddy_restore_files::restore( backupbuddy_core::getBackupDirectory() . $archive_file, $files, $finalPath = ABSPATH ); + $restore_result = ob_get_clean(); + pb_backupbuddy::flush(); return array('restore_result' => $restore_result); - } - + } + function get_backup_list( $type = 'default', $subsite_mode = false ) { $backups = array(); $backup_sort_dates = array(); - + $files = glob( backupbuddy_core::getBackupDirectory() . 'backup*.zip' ); if ( ! is_array( $files ) ) { $files = array(); } - + $files2 = glob( backupbuddy_core::getBackupDirectory() . 'snapshot*.zip' ); if ( ! is_array( $files2 ) ) { $files2 = array(); } - + $files = array_merge( $files, $files2 ); - + if ( is_array( $files ) && !empty( $files ) ) { // For robustness. Without open_basedir the glob() function returns an empty array for no match. With open_basedir in effect the glob() function returns a boolean false for no match. - + $backup_prefix = backupbuddy_core::backup_prefix(); // Backup prefix for this site. Used for MS checking that this user can see this backup. foreach( $files as $file_id => $file ) { - + if ( ( $subsite_mode === true ) && is_multisite() ) { // If a Network and NOT the superadmin must make sure they can only see the specific subsite backups for security purposes. - + // Only allow viewing of their own backups. if ( ! strstr( $file, $backup_prefix ) ) { unset( $files[$file_id] ); // Remove this backup from the list. This user does not have access to it. continue; // Skip processing to next file. } } - + $serial = backupbuddy_core::get_serial_from_file( $file ); - + $options = array(); if ( file_exists( backupbuddy_core::getLogDirectory() . 'fileoptions/' . $serial . '.txt' ) ) { require_once( pb_backupbuddy::plugin_path() . '/classes/fileoptions.php' ); @@ -987,7 +990,7 @@ class MainWP_Child_Back_Up_Buddy { $backup_options = ''; } $backup_integrity = backupbuddy_core::backup_integrity_check( $file, $backup_options, $options ); - + // Backup status. $pretty_status = array( true => 'Good', // v4.0+ Good. @@ -995,7 +998,7 @@ class MainWP_Child_Back_Up_Buddy { false => 'Bad', // v4.0+ Bad. 'fail' => 'Bad', // Pre-v4.0 Bad. ); - + // Backup type. $pretty_type = array( 'full' => 'Full', @@ -1004,15 +1007,15 @@ class MainWP_Child_Back_Up_Buddy { 'themes' => 'Themes', 'plugins' => 'Plugins', ); - - + + // Defaults... $detected_type = ''; $file_size = ''; $modified = ''; $modified_time = 0; $integrity = ''; - + $main_string = 'Warn#284.'; if ( is_array( $backup_integrity ) ) { // Data intact... put it all together. // Calculate time ago. @@ -1020,7 +1023,7 @@ class MainWP_Child_Back_Up_Buddy { if ( isset( $backup_integrity['modified'] ) ) { $time_ago = pb_backupbuddy::$format->time_ago( $backup_integrity['modified'] ) . ' ago'; } - + $detected_type = pb_backupbuddy::$format->prettify( $backup_integrity['detected_type'], $pretty_type ); if ( $detected_type == '' ) { $detected_type = backupbuddy_core::pretty_backup_type( backupbuddy_core::getBackupTypeFromFile( $file ) ); @@ -1039,7 +1042,7 @@ class MainWP_Child_Back_Up_Buddy { ; } } - + $file_size = pb_backupbuddy::$format->file_size( $backup_integrity['size'] ); $modified = pb_backupbuddy::$format->date( pb_backupbuddy::$format->localize_time( $backup_integrity['modified'] ), 'l, F j, Y - g:i:s a' ); $modified_time = $backup_integrity['modified']; @@ -1048,11 +1051,11 @@ class MainWP_Child_Back_Up_Buddy { } else { // v4.0+ $status = $backup_integrity['is_ok']; } - - + + // Calculate main row string. if ( $type == 'default' ) { // Default backup listing. - $download_url = '/wp-admin/admin-ajax.php?action=mainwp_backupbuddy_download_archive&backupbuddy_backup=' . basename( $file ) . '&_wpnonce=' . MainWP_Helper::create_nonce_without_session( 'mainwp_download_backup' ); + $download_url = '/wp-admin/admin-ajax.php?action=mainwp_backupbuddy_download_archive&backupbuddy_backup=' . basename( $file ) . '&_wpnonce=' . MainWP_Helper::create_nonce_without_session( 'mainwp_download_backup' ); $main_string = '' . $modified . ' (' . $time_ago . ')'; } elseif ( $type == 'migrate' ) { // Migration backup listing. $main_string = '' . $modified . ' (' . $time_ago . ')'; @@ -1073,20 +1076,20 @@ class MainWP_Child_Back_Up_Buddy { } $integrity .= ' '; $integrity .= '
' . __( 'View Details', 'mainwp-child' ) . '
'; - + $sumLogFile = backupbuddy_core::getLogDirectory() . 'status-' . $serial . '_' . pb_backupbuddy::$options['log_serial'] . '.txt'; if ( file_exists( $sumLogFile ) ) { $integrity .= '
' . __( 'View Log', 'mainwp-child' ) . '
'; } - + } // end if is_array( $backup_options ). - + // No integrity check for themes or plugins types. $raw_type = backupbuddy_core::getBackupTypeFromFile( $file ); if ( ( 'themes' == $raw_type ) || ( 'plugins' == $raw_type ) ) { $integrity = 'n/a'; } - + $backups[basename( $file )] = array( array( basename( $file ), $main_string . '
' . basename( $file ) . '' ), $detected_type, @@ -1112,24 +1115,24 @@ class MainWP_Child_Back_Up_Buddy { unset( $backups ); return $sorted_backups; -} // End backups_list(). - - function get_recent_backup_list () { + } // End backups_list(). + + function get_recent_backup_list () { $recentBackups_list = glob( backupbuddy_core::getLogDirectory() . 'fileoptions/*.txt' ); if ( ! is_array( $recentBackups_list ) ) { $recentBackups_list = array(); } - + $recentBackups = array(); if ( count( $recentBackups_list ) > 0 ) { - + // Backup type. $pretty_type = array( 'full' => 'Full', 'db' => 'Database', 'files' => 'Files', ); - + foreach( $recentBackups_list as $backup_fileoptions ) { require_once( pb_backupbuddy::plugin_path() . '/classes/fileoptions.php' ); @@ -1182,8 +1185,8 @@ class MainWP_Child_Back_Up_Buddy { $backupType = '
' . pb_backupbuddy::$format->prettify( $backup['profile']['type'], $pretty_type ) . ' ' - . $backup['profile']['title'] . - '
'; + . $backup['profile']['title'] . + ''; } else { $backupType = backupbuddy_core::pretty_backup_type( backupbuddy_core::getBackupTypeFromFile( $backup['archive_file'] ) ); if ( '' == $backupType ) { @@ -1239,28 +1242,28 @@ class MainWP_Child_Back_Up_Buddy { pb_backupbuddy_aasort( $recentBackups, 'start_timestamp' ); // Sort by multidimensional array with key start_timestamp. $recentBackups = array_reverse( $recentBackups ); // Reverse array order to show newest first. - } - - return $recentBackups; -} - - function delete_scheduled_backup() { + } + + return $recentBackups; + } + + function delete_scheduled_backup() { $schedule_ids = $_POST['schedule_ids']; $schedule_ids = explode(',', $schedule_ids); - + if (empty($schedule_ids)) { return array('error' => __( 'Empty schedule ids', 'mainwp-child' )); - } + } foreach ($schedule_ids as $sch_id) { - if ( isset( pb_backupbuddy::$options['schedules'][$sch_id] ) ) { + if ( isset( pb_backupbuddy::$options['schedules'][$sch_id] ) ) { unset( pb_backupbuddy::$options['schedules'][$sch_id] ); } } pb_backupbuddy::save(); - $information['result'] = 'SUCCESS'; + $information['result'] = 'SUCCESS'; return $information; } - + function view_log() { $serial = $_POST[ 'serial' ]; $logFile = backupbuddy_core::getLogDirectory() . 'status-' . $serial . '_sum_' . pb_backupbuddy::$options['log_serial'] . '.txt'; @@ -1273,50 +1276,50 @@ class MainWP_Child_Back_Up_Buddy { $lines = explode( "\n", $lines ); ob_start(); ?> - +

+ ?>

Log file:
Last modified: ' . pb_backupbuddy::$format->date( filemtime( $logFile ) ) . ' (' . pb_backupbuddy::$format->time_ago( filemtime( $logFile ) ) . ' ago)'; ?>

- 'SUCCESS', 'html_log' => $html); } - + function view_detail() { - + $serial = $_POST['serial']; $serial = str_replace( '/\\', '', $serial ); pb_backupbuddy::load(); - + require_once( pb_backupbuddy::plugin_path() . '/classes/fileoptions.php' ); pb_backupbuddy::status( 'details', 'Fileoptions instance #27.' ); $optionsFile = backupbuddy_core::getLogDirectory() . 'fileoptions/' . $serial . '.txt'; $backup_options = new pb_backupbuddy_fileoptions( $optionsFile, $read_only = true ); if ( true !== ( $result = $backup_options->is_ok() ) ) { - return array('error' => __('Unable to access fileoptions data file.', 'mainwp-child' ) . ' Error: ' . $result ); + return array('error' => __('Unable to access fileoptions data file.', 'mainwp-child' ) . ' Error: ' . $result ); } ob_start(); $integrity = $backup_options->options['integrity']; @@ -1534,1208 +1537,1217 @@ class MainWP_Child_Back_Up_Buddy { echo print_r( $backup_options->options, true ); echo '

'; echo '

'; - - $html = ob_get_clean(); + + $html = ob_get_clean(); pb_backupbuddy::flush(); return array('result' => 'SUCCESS', 'html_detail' => $html); } - + function reset_integrity() { - $_GET['reset_integrity'] = $_POST['reset_integrity']; - $information['backup_list'] = $this->get_backup_list(); - $information['result'] = 'SUCCESS'; - return $information; + $_GET['reset_integrity'] = $_POST['reset_integrity']; + $information['backup_list'] = $this->get_backup_list(); + $information['result'] = 'SUCCESS'; + return $information; } - - function download_archive() { - - if ( ! isset( $_GET['_wpnonce'] ) || empty( $_GET['_wpnonce'] ) ) { + + function download_archive() { + + if ( ! isset( $_GET['_wpnonce'] ) || empty( $_GET['_wpnonce'] ) ) { die( '-1' ); } if ( ! MainWP_Helper::verify_nonce_without_session( $_GET['_wpnonce'], 'mainwp_download_backup' ) ) { die( '-2' ); } - - backupbuddy_core::verifyAjaxAccess(); - if ( is_multisite() && !current_user_can( 'manage_network' ) ) { // If a Network and NOT the superadmin must make sure they can only download the specific subsite backups for security purposes. + backupbuddy_core::verifyAjaxAccess(); - if ( !strstr( pb_backupbuddy::_GET( 'backupbuddy_backup' ), backupbuddy_core::backup_prefix() ) ) { - die( 'Access Denied. You may only download backups specific to your Multisite Subsite. Only Network Admins may download backups for another subsite in the network.' ); - } - } + if ( is_multisite() && !current_user_can( 'manage_network' ) ) { // If a Network and NOT the superadmin must make sure they can only download the specific subsite backups for security purposes. - if ( !file_exists( backupbuddy_core::getBackupDirectory() . pb_backupbuddy::_GET( 'backupbuddy_backup' ) ) ) { // Does not exist. - die( 'Error #548957857584784332. The requested backup file does not exist. It may have already been deleted.' ); - } - - $abspath = str_replace( '\\', '/', ABSPATH ); - $backup_dir = str_replace( '\\', '/', backupbuddy_core::getBackupDirectory() ); - - if ( FALSE === stristr( $backup_dir, $abspath ) ) { - die( 'Error #5432532. You cannot download backups stored outside of the WordPress web root. Please use FTP or other means.' ); - } - - $sitepath = str_replace( $abspath, '', $backup_dir ); - $download_url = rtrim( site_url(), '/\\' ) . '/' . trim( $sitepath, '/\\' ) . '/' . pb_backupbuddy::_GET( 'backupbuddy_backup' ); - - if ( pb_backupbuddy::$options['lock_archives_directory'] == '1' ) { - - if ( file_exists( backupbuddy_core::getBackupDirectory() . '.htaccess' ) ) { - $unlink_status = @unlink( backupbuddy_core::getBackupDirectory() . '.htaccess' ); - if ( $unlink_status === false ) { - die( 'Error #844594. Unable to temporarily remove .htaccess security protection on archives directory to allow downloading. Please verify permissions of the BackupBuddy archives directory or manually download via FTP.' ); - } - } - - header( 'Location: ' . $download_url ); - ob_clean(); - flush(); - sleep( 8 ); - - $htaccess_creation_status = @file_put_contents( backupbuddy_core::getBackupDirectory() . '.htaccess', 'deny from all' ); - if ( $htaccess_creation_status === false ) { - die( 'Error #344894545. Security Warning! Unable to create security file (.htaccess) in backups archive directory. This file prevents unauthorized downloading of backups should someone be able to guess the backup location and filenames. This is unlikely but for best security should be in place. Please verify permissions on the backups directory.' ); - } - - } else { - header( 'Location: ' . $download_url ); - } - die(); - } - - function create_backup() { - $requested_profile = $_POST['profile_id']; - - if (!isset(pb_backupbuddy::$options['profiles'][ $requested_profile ])) { - return array('error' => 'Invalid Profile. Not found.'); - } - - require_once( pb_backupbuddy::plugin_path() . '/classes/backup.php' ); - $newBackup = new pb_backupbuddy_backup(); - - $profile_array = pb_backupbuddy::$options['profiles'][ $requested_profile ]; - $serial_override = pb_backupbuddy::random_string( 10 ); - - if ( $newBackup->start_backup_process( - $profile_array, - 'manual', // trigger - array(), - isset($_POST['post_backup_steps']) && is_array($_POST['post_backup_steps']) ? $_POST['post_backup_steps'] : array(), - '', - $serial_override, - '', // export_plugins - '', // direction - '' // deployDestination - ) !== true ) { - return array('error' => __('Fatal Error #4344443: Backup failure. Please see any errors listed in the Status Log for details.', 'it-l10n-backupbuddy' )); - } - return array('result' => 'SUCCESS'); - } - - function start_backup() { - require_once( pb_backupbuddy::plugin_path() . '/classes/backup.php' ); - $newBackup = new pb_backupbuddy_backup(); - $data = $_POST['data']; - if (is_array($data) && isset($data['serial_override'])) { - if ( $newBackup->start_backup_process( - $data['profile_array'], - $data['trigger'], - array(), - isset($data['post_backup_steps']) && is_array($data['post_backup_steps']) ? $data['post_backup_steps'] : array(), - '', - $data['serial_override'], - isset($data['export_plugins']) ? $data['export_plugins'] : '', - $data['direction'], - isset($data['deployDestination']) ? $data['deployDestination'] : '' - ) !== true ) { - return array('error' => __('Fatal Error #4344443: Backup failure. Please see any errors listed in the Status Log for details.', 'it-l10n-backupbuddy' )); - } - } else { - return array('error' => 'Invalid backup request.'); - } - - return array('ok' => 1); - - } - - function backup_status() { - $data = $_POST['data']; - $result = ''; - if (is_array($data) && isset($data['serial'])) { - ob_start(); - backupbuddy_api::getBackupStatus( $data['serial'], $data['specialAction'], $data['initwaitretrycount'], $data['sqlFile'], $echo = true ); - $result = ob_get_clean(); - } else { - return array('error' => 'Invalid backup request.'); - } - return array('ok' => 1, 'result' => $result); - } - - function stop_backup() { - $serial = $_POST['serial']; - set_transient( 'pb_backupbuddy_stop_backup-' . $serial, true, ( 60*60*24 ) ); - return array('ok' => 1); - } - - function remote_save() { - $data = isset($_POST['data']) ? $_POST['data'] : false; - $destination_id = isset($_POST['destination_id']) ? $_POST['destination_id'] : 0; - if (is_array($data)) { - if (isset(pb_backupbuddy::$options['remote_destinations'][$destination_id])) { // update - pb_backupbuddy::$options['remote_destinations'][$destination_id] = array_merge( pb_backupbuddy::$options['remote_destinations'][$destination_id], $data ); - } else { // add new - $data['token'] = pb_backupbuddy::$options['dropboxtemptoken']; - pb_backupbuddy::$options['remote_destinations'][$destination_id] = $data; - } - pb_backupbuddy::save(); - return array('ok' => 1); - } else { - return array('error' => 'Invalid request.'); - } - } - - function remote_delete() { - $destination_id = isset($_POST['destination_id']) ? $_POST['destination_id'] : null; - if ($destination_id !== null) { - require_once( pb_backupbuddy::plugin_path() . '/destinations/bootstrap.php' ); - $delete_response = pb_backupbuddy_destinations::delete_destination( $destination_id, true ); - - if ( $delete_response !== true ) { - return array('error' => $delete_response); - } else { - return array('ok' => 1); - } - } else { - return array('error' => 'Invalid request.'); - } - } - - function remote_send() { - - $destination_id = isset($_POST['destination_id']) ? $_POST['destination_id'] : null; - $file = isset($_POST['file']) ? $_POST['file'] : null; - $trigger = isset($_POST['trigger']) ? $_POST['trigger'] : 'manual'; - - if ( $file != 'importbuddy.php' ) { - $backup_file = backupbuddy_core::getBackupDirectory() . $file; - if ( ! file_exists( $backup_file ) ) { // Error if file to send did not exist! - $error_message = 'Unable to find file `' . $backup_file . '` to send. File does not appear to exist. You can try again in a moment or turn on full error logging and try again to log for support.'; - pb_backupbuddy::status( 'error', $error_message ); - return array( 'error' => $error_message); - } - if ( is_dir( $backup_file ) ) { // Error if a directory is trying to be sent. - $error_message = 'You are attempting to send a directory, `' . $backup_file . '`. Try again and verify there were no javascript errors.'; - pb_backupbuddy::status( 'error', $error_message ); - return array( 'error' => $error_message); - } - } else { - $backup_file = ''; - } - - if ( isset($_POST['send_importbuddy']) && $_POST['send_importbuddy'] == '1' ) { - $send_importbuddy = true; - pb_backupbuddy::status( 'details', 'Cron send to be scheduled with importbuddy sending.' ); - } else { - $send_importbuddy = false; - pb_backupbuddy::status( 'details', 'Cron send to be scheduled WITHOUT importbuddy sending.' ); - } - - if ( isset($_POST['delete_after']) && $_POST['delete_after'] == '1' ) { - $delete_after = true; - pb_backupbuddy::status( 'details', 'Remote send set to delete after successful send.' ); - } else { - $delete_after = false; - pb_backupbuddy::status( 'details', 'Remote send NOT set to delete after successful send.' ); - } - - if ( !isset( pb_backupbuddy::$options['remote_destinations'][$destination_id] ) ) { - return array( 'error' => 'Error #833383: Invalid destination ID `' . htmlentities( $destination_id ) . '`.' ); - } - - - // For Stash we will check the quota prior to initiating send. - if ( pb_backupbuddy::$options['remote_destinations'][$destination_id]['type'] == 'stash' ) { - // Pass off to destination handler. - require_once( pb_backupbuddy::plugin_path() . '/destinations/bootstrap.php' ); - $send_result = pb_backupbuddy_destinations::get_info( 'stash' ); // Used to kick the Stash destination into life. - $stash_quota = pb_backupbuddy_destination_stash::get_quota( pb_backupbuddy::$options['remote_destinations'][$destination_id], true ); - - if ( isset( $stash_quota['error'] ) ) { - return array( 'error' => ' Error accessing Stash account. Send aborted. Details: `' . implode( ' - ', $stash_quota['error'] ) . '`.'); - } - - if ( $backup_file != '' ) { - $backup_file_size = filesize( $backup_file ); - } else { - $backup_file_size = 50000; - } - if ( ( $backup_file_size + $stash_quota['quota_used'] ) > $stash_quota['quota_total'] ) { - ob_start(); - echo "You do not have enough Stash storage space to send this file. Please upgrade your Stash storage or delete files to make space.\n\n"; - echo 'Attempting to send file of size ' . pb_backupbuddy::$format->file_size( $backup_file_size ) . ' but you only have ' . $stash_quota['quota_available_nice'] . ' available. '; - echo 'Currently using ' . $stash_quota['quota_used_nice'] . ' of ' . $stash_quota['quota_total_nice'] . ' (' . $stash_quota['quota_used_percent'] . '%).'; - $error = ob_get_clean(); - return array( 'error' => $error ); - } else { - if ( isset( $stash_quota['quota_warning'] ) && ( $stash_quota['quota_warning'] != '' ) ) { - $warning = 'Warning: ' . $stash_quota['quota_warning'] . "\n\n"; - $success_output = true; - } - } - - } // end if Stash. - - pb_backupbuddy::status( 'details', 'Scheduling cron to send to this remote destination...' ); - - $schedule_result = backupbuddy_core::schedule_single_event( time(), 'remote_send', array( $destination_id, $backup_file, $trigger, $send_importbuddy, $delete_after ) ); - if ( $schedule_result === FALSE ) { - $error = 'Error scheduling file transfer. Please check your BackupBuddy error log for details. A plugin may have prevented scheduling or the database rejected it.'; - pb_backupbuddy::status( 'error', $error ); - return array( 'error' => $error); - } else { - pb_backupbuddy::status( 'details', 'Cron to send to remote destination scheduled.' ); - } - if ( '1' != pb_backupbuddy::$options['skip_spawn_cron_call'] ) { - update_option( '_transient_doing_cron', 0 ); // Prevent cron-blocking for next item. - spawn_cron( time() + 150 ); // Adds > 60 seconds to get around once per minute cron running limit. - } - return array( 'ok' => 1); - } - - function get_main_log() { - $log_file = backupbuddy_core::getLogDirectory() . 'log-' . pb_backupbuddy::$options['log_serial'] . '.txt'; - ob_start(); - if ( file_exists( $log_file ) ) { - readfile( $log_file ); - } else { - echo __('Nothing has been logged.', 'it-l10n-backupbuddy' ); - } - $result = ob_get_clean(); - return array('result' => $result ); - } - - function settings_other() { - - $other_action = $_POST['other_action']; - - $message = ''; - $error = ''; - - if ( 'cleanup_now' == $other_action ) { - $message = 'Performing cleanup procedures now trimming old files and data.'; - require_once( pb_backupbuddy::plugin_path() . '/classes/housekeeping.php' ); - backupbuddy_housekeeping::run_periodic( 0 ); // 0 cleans up everything even if not very old. - - } else if ( 'delete_tempfiles_now' == $other_action) { - $tempDir = backupbuddy_core::getTempDirectory(); - $logDir = backupbuddy_core::getLogDirectory(); - $message = 'Deleting all files contained within `' . $tempDir . '` and `' . $logDir . '`.' ; - pb_backupbuddy::$filesystem->unlink_recursive( $tempDir ); - pb_backupbuddy::$filesystem->unlink_recursive( $logDir ); - pb_backupbuddy::anti_directory_browsing( $logDir, $die = false ); // Put log dir back in place. - } else if ( 'reset_log' == $other_action ) { - $log_file = backupbuddy_core::getLogDirectory() . 'log-' . pb_backupbuddy::$options['log_serial'] . '.txt'; - if ( file_exists( $log_file ) ) { - @unlink( $log_file ); - } - if ( file_exists( $log_file ) ) { // Didnt unlink. - $error = 'Unable to clear log file. Please verify permissions on file `' . $log_file . '`.'; - } else { // Unlinked. - $message = 'Cleared log file.'; - } - } else if ( 'reset_disalerts' == $other_action) { - pb_backupbuddy::$options['disalerts'] = array(); - pb_backupbuddy::save(); - $message = 'Dismissed alerts have been reset. They may now be visible again.'; - - } else if ( 'cancel_running_backups' == $other_action) { - require_once( pb_backupbuddy::plugin_path() . '/classes/fileoptions.php' ); - - $fileoptions_directory = backupbuddy_core::getLogDirectory() . 'fileoptions/'; - $files = glob( $fileoptions_directory . '*.txt' ); - if ( ! is_array( $files ) ) { - $files = array(); - } - $cancelCount = 0; - for ($x = 0; $x <= 3; $x++) { // Try this a few times since there may be race conditions on an open file. - foreach( $files as $file ) { - pb_backupbuddy::status( 'details', 'Fileoptions instance #383.' ); - - $backup_options = new pb_backupbuddy_fileoptions( $file, $read_only = false ); - if ( true !== ( $result = $backup_options->is_ok() ) ) { - pb_backupbuddy::status( 'error', 'Error retrieving fileoptions file `' . $file . '`. Err 335353266.' ); - } else { - if ( empty( $backup_options->options['finish_time'] ) || ( ( FALSE !== $backup_options->options['finish_time'] ) && ( '-1' != $backup_options->options['finish_time'] ) ) ) { - $backup_options->options['finish_time'] = -1; // Force marked as cancelled by user. - $backup_options->save(); - $cancelCount++; - } - } - } - sleep( 1 ); - } - - $message = 'Marked all timed out or running backups & transfers as officially cancelled (`' . $cancelCount . '` total found).'; - } - - return array('_error' => $error, '_message' => $message); - } - - function malware_scan() { - - backupbuddy_core::schedule_single_event( time(), 'housekeeping', array() ); - update_option( '_transient_doing_cron', 0 ); - spawn_cron( time() + 150 ); - - ob_start(); - - if ( ! defined( 'pluginbuddy_importbuddy' ) ) { - $url = home_url(); - } else { - $url = str_replace( $_SERVER['QUERY_STRING'], '', $_SERVER['REQUEST_URI'] ); - $url = str_replace( basename( $url ) , '', $url ); - $url = 'http://' . $_SERVER['HTTP_HOST'] . $url; - } - ?> - - - - start_metabox( __( 'Malware Scan URL', 'it-l10n-backupbuddy' ), true, 'width: 100%;' ); - - ?> - - - - Scanning `' . $url . '`.

'; - if ( !defined( 'pluginbuddy_importbuddy' ) ) { - $scan = get_transient( 'pb_backupbuddy_malwarescan' ); - } else { - $scan = false; - } - - if ( false === $scan ) { - flush(); - - $scan = wp_remote_get( - 'http://sitecheck.sucuri.net/scanner/?scan=' . urlencode( $url ) . '&serialized&clear=true', - array( - 'method' => 'GET', - 'timeout' => 45, - 'redirection' => 5, - 'httpversion' => '1.0', - 'blocking' => true, - 'headers' => array(), - 'body' => null, - 'cookies' => array() - ) - ); - - if ( is_wp_error( $scan ) ) { - pb_backupbuddy::alert( __('ERROR #24452. Unable to load Malware Scan results. Details:', 'it-l10n-backupbuddy' ). ' ' . $scan->get_error_message(), true ); - $scan = 'N;'; - } else { - $scan = $scan['body']; - set_transient( 'pb_backupbuddy_malwarescan', $scan, 60*60*1 ); // 1 hour cache. - } - - } - - $continue_2 = true; - if ( substr( $scan, 0, 2 ) == 'N;' ) { - echo __('An error was encountered attempting to scan this site.','it-l10n-backupbuddy' ), '
'; - echo __('An internet connection is required and this site must be accessible on the public internet.', 'it-l10n-backupbuddy' ); - echo '
'; - $scan = array(); - $continue_2 = false; - } else { - $scan = maybe_unserialize( $scan ); - //echo '
';
-                                    //print_r( $scan );
-                                    //echo '
'; - } - - } - - pb_backupbuddy::$ui->end_metabox(); - ?> - - - - $array_item ) { - if ( is_array( $array_item ) ) { - $array[$array_key] = lined_array( $array_item ); - } - } - //return implode( '
', $array ); - $return = ''; - foreach( $array as $array_item ) { - $return .= $array_item . '
'; - } - return $return; - } else { - if ( empty( $array ) ) { - return ''.__('none', 'it-l10n-backupbuddy' ).'
'; - } else { - return $array . '
'; - } - } - } - - if ( !empty( $scan['MALWARE'] ) && ( $scan['MALWARE'] != 'E' ) ) { - echo '

', __('Warning: Possible Malware Detected!', 'it-l10n-backupbuddy' ), '

',__('See details below.', 'it-l10n-backupbuddy' ), '
'; - } - - ?> - - -
-
-
- - - - - - - - - - - - - - - - - -
-
-
- $result); - } - - - function live_setup() { - - $errors = array(); - - $archive_types = array( - 'db' => __( 'Database Backup', 'it-l10n-backupbuddy' ), - 'full' => __( 'Full Backup', 'it-l10n-backupbuddy' ), - 'plugins' => __( 'Plugins Backup', 'it-l10n-backupbuddy' ), - 'themes' => __( 'Themes Backup', 'it-l10n-backupbuddy' ), - ); - - $archive_periods = array( - 'daily', - 'weekly', - 'monthly', - 'yearly', - ); - - - if ( ( '' == $_POST['live_username'] ) || ( '' == $_POST['live_password'] ) ) { // A field is blank. - $errors[] = 'You must enter your iThemes username & password to log in to BackupBuddy Stash Live.'; - } else { // Username and password provided. - - require_once( pb_backupbuddy::plugin_path() . '/destinations/stash2/class.itx_helper2.php' ); - require_once( pb_backupbuddy::plugin_path() . '/destinations/stash2/init.php' ); - require_once( pb_backupbuddy::plugin_path() . '/destinations/live/init.php' ); - global $wp_version; - - $itxapi_username = strtolower( $_POST['live_username'] ); - $password_hash = iThemes_Credentials::get_password_hash( $itxapi_username, $_POST['live_password'] ); - $access_token = ITXAPI_Helper2::get_access_token( $itxapi_username, $password_hash, site_url(), $wp_version ); - - $settings = array( - 'itxapi_username' => $itxapi_username, - 'itxapi_password' => $access_token, - ); - $response = pb_backupbuddy_destination_stash2::stashAPI( $settings, 'connect' ); - - if ( ! is_array( $response ) ) { // Error message. - $errors[] = print_r( $response, true ); - } else { - if ( isset( $response['error'] ) ) { - $errors[] = $response['error']['message']; - } else { - if ( isset( $response['token'] ) ) { - $itxapi_token = $response['token']; - } else { - $errors[] = 'Error #2308832: Unexpected server response. Token missing. Check your BackupBuddy Stash Live login and try again. Detailed response: `' . print_r( $response, true ) .'`.'; - } - } - } - - // If we have the token then create the Live destination. - if ( isset( $itxapi_token ) ) { - if ( count( pb_backupbuddy::$options['remote_destinations'] ) > 0 ) { - $nextDestKey = max( array_keys( pb_backupbuddy::$options['remote_destinations'] ) ) + 1; - } else { // no destinations yet. first index. - $nextDestKey = 0; - } - - pb_backupbuddy::$options['remote_destinations'][ $nextDestKey ] = pb_backupbuddy_destination_live::$default_settings; - pb_backupbuddy::$options['remote_destinations'][ $nextDestKey ]['itxapi_username'] = $_POST['live_username']; - pb_backupbuddy::$options['remote_destinations'][ $nextDestKey ]['itxapi_token'] = $itxapi_token; - pb_backupbuddy::$options['remote_destinations'][ $nextDestKey ]['title'] = 'My BackupBuddy Stash Live'; - - // Notification email. - pb_backupbuddy::$options['remote_destinations'][ $nextDestKey ]['email'] = $_POST['email']; - - // Archive limits. - foreach( $archive_types as $archive_type => $archive_type_name ) { - foreach( $archive_periods as $archive_period ) { - $settings_name = 'limit_' . $archive_type . '_' . $archive_period; - pb_backupbuddy::$options['remote_destinations'][ $nextDestKey ][ $settings_name ] = $_POST['live_settings'][$settings_name]; - } - } - - if ( '1' == $_POST['send_snapshot_notification'] ) { - pb_backupbuddy::$options['remote_destinations'][ $nextDestKey ]['send_snapshot_notification'] = $_POST['send_snapshot_notification']; - } else { - pb_backupbuddy::$options['remote_destinations'][ $nextDestKey ]['send_snapshot_notification'] = '0'; - } - - pb_backupbuddy::save(); - $destination_id = $nextDestKey; - - // Send new settings for archive limiting to Stash API. - backupbuddy_live::send_trim_settings(); - - - - // Set first run of BackupBuddy Stash Live so it begins immediately. - $cronArgs = array(); - $schedule_result = backupbuddy_core::schedule_single_event( time(), 'live_periodic', $cronArgs ); - if ( true === $schedule_result ) { - pb_backupbuddy::status( 'details', 'Next Live Periodic chunk step cron event scheduled.' ); - } else { - pb_backupbuddy::status( 'error', 'Next Live Periodic chunk step cron event FAILED to be scheduled.' ); - } - if ( '1' != pb_backupbuddy::$options['skip_spawn_cron_call'] ) { - pb_backupbuddy::status( 'details', 'Spawning cron now.' ); - update_option( '_transient_doing_cron', 0 ); // Prevent cron-blocking for next item. - spawn_cron( time() + 150 ); // Adds > 60 seconds to get around once per minute cron running limit. - } - - } - - } // end if user and pass set. - - - if ( 0 == count( $errors ) ) { - pb_backupbuddy::save(); - $data = pb_backupbuddy::$options['remote_destinations'][ $destination_id ]; - return array( 'destination_id' => $destination_id, 'data' => $data); - } else { - return array( 'errors' => $errors ); - } - - } - - function live_save_settings() { - $data = $_POST['data']; - $new_destination_id = $_POST['destination_id']; - - - require_once( pb_backupbuddy::plugin_path() . '/destinations/bootstrap.php' ); - require_once( pb_backupbuddy::plugin_path() . '/destinations/live/live.php' ); - require_once( pb_backupbuddy::plugin_path() . '/destinations/live/live_periodic.php' ); - - $destination_id = backupbuddy_live::getLiveID(); - $destination_settings = isset(pb_backupbuddy::$options['remote_destinations'][$destination_id]) ? pb_backupbuddy::$options['remote_destinations'][$destination_id] : array(); - - $check_current = !empty($destination_settings) ? true : false; - - $error = ''; - if ( $new_destination_id && is_array($data) ) { - $itxapi_username = isset($destination_settings['itxapi_username']) ? $destination_settings['itxapi_username'] : ''; - $itxapi_token = isset($destination_settings['itxapi_token']) ? $destination_settings['itxapi_token'] : ''; - $destination_settings = array_merge( $destination_settings, $data ); - $destination_settings['itxapi_username'] = $itxapi_username; - $destination_settings['itxapi_token'] = $itxapi_token; - pb_backupbuddy::$options['remote_destinations'][$new_destination_id] = $destination_settings; - - if ($check_current && $destination_id != $new_destination_id) { - unset(pb_backupbuddy::$options['remote_destinations'][$destination_id]); - } - - pb_backupbuddy::save(); - //pb_backupbuddy::alert( __( 'Settings saved. Restarting Live process so they take immediate effect.', 'it-l10n-backupbuddy' ) ); - set_transient( 'backupbuddy_live_jump', array( 'daily_init', array() ), 60*60*48 ); // Tells Live process to restart from the beginning (if mid-process) so new settigns apply. - - backupbuddy_live::send_trim_settings(); - return array('ok' => 1); - } else { - $error = 'Invalid data.'; - } - return array('error' => $error); - } - - function live_action_disconnect() { - $error = ''; - $liveDestinationID = $_POST['destination_id']; - - $return = array(); - if ($liveDestinationID) { - if (isset(pb_backupbuddy::$options['remote_destinations'][ $liveDestinationID ])) { - // Clear destination settings. - unset( pb_backupbuddy::$options['remote_destinations'][ $liveDestinationID ] ); - pb_backupbuddy::save(); - // Clear cached Live credentials. - require_once( pb_backupbuddy::plugin_path() . '/destinations/live/init.php' ); - delete_transient( pb_backupbuddy_destination_live::LIVE_ACTION_TRANSIENT_NAME ); - } else { - $error = 'Error: Not found.'; - } - $return['ok'] = 1; - } else { - $error = 'Error: Empty destination id.'; - } - - if (!empty($error)) - $return['error'] = $error; - - return $return; - } - - function live_action() { - $action = $_POST['live_action']; - $error = $message = ''; - - require_once( pb_backupbuddy::plugin_path() . '/destinations/live/live_periodic.php' ); - $state = backupbuddy_live_periodic::get_stats(); - - $destination_id = backupbuddy_live::getLiveID(); - $destination = backupbuddy_live_periodic::get_destination_settings(); - - if ( 'clear_log' == $action ) { - $sumLogFile = backupbuddy_core::getLogDirectory() . 'status-live_periodic_' . pb_backupbuddy::$options['log_serial'] . '.txt'; - @unlink( $sumLogFile ); - if ( file_exists( $sumLogFile ) ) { - $error = 'Error #893489322: Unable to clear log file `' . $sumLogFile . '`. Check permissions or manually delete.' ; - } else { - $message = 'Log file cleared.'; - } - - } else if ( 'create_snapshot' == $action ) { // < 100% backed up _OR_ ( we are on a step other than daily_init and the last_activity is more recent than the php runtime ) - if ( true === backupbuddy_api::runLiveSnapshot() ) { - //pb_backupbuddy::alert( '

' . __( 'Verifying everything is up to date before Snapshot', 'it-l10n-backupbuddy' ) . '

' . __( 'Please wait while we verify your backup is completely up to date before we create the Snapshot. This may take a few minutes...', 'it-l10n-backupbuddy' ) . '

', false, '', 'backupbuddy_live_snapshot_verify_uptodate' ); - $message = '

' . __( 'Verifying everything is up to date before Snapshot', 'it-l10n-backupbuddy' ) . '

' . __( 'Please wait while we verify your backup is completely up to date before we create the Snapshot. This may take a few minutes...', 'it-l10n-backupbuddy' ) . '

'; - require( pb_backupbuddy::plugin_path() . '/destinations/live/_manual_snapshot.php' ); - } - - } else if ( 'pause_periodic' == $action ) { - backupbuddy_api::setLiveStatus( $pause_continuous = '', $pause_periodic = true ); - $destination = pb_backupbuddy::$options['remote_destinations'][$destination_id]; // Update local var. - //pb_backupbuddy::disalert( '', __( 'Live File Backup paused. It may take a moment for current processes to finish.', 'it-l10n-backupbuddy' ) ); - $message = __( 'Live File Backup paused. It may take a moment for current processes to finish.', 'it-l10n-backupbuddy' ); - include( pb_backupbuddy::plugin_path() . '/destinations/live/_stats.php' ); // Recalculate stats. - } else if ( 'resume_periodic' == $action ) { - $launchNowText = ' ' . __( 'Unpaused but not running now.', 'it-l10n-backupbuddy' ); - $start_run = false; - if ( '1' != pb_backupbuddy::_GET( 'skip_run_live_now' ) ) { - $launchNowText = ''; - $start_run = true; - } - - backupbuddy_api::setLiveStatus( $pause_continuous = '', $pause_periodic = false, $start_run ); - //pb_backupbuddy::disalert( '', __( 'Live File Backup has resumed.', 'it-l10n-backupbuddy' ) . $launchNowText ); - $message = __( 'Live File Backup has resumed.', 'it-l10n-backupbuddy' ) . $launchNowText; - include( pb_backupbuddy::plugin_path() . '/destinations/live/_stats.php' ); // Recalculate stats. - } else if ( 'pause_continuous' == $action ) { - backupbuddy_api::setLiveStatus( $pause_continuous = true, $pause_periodic = '' ); - $destination = pb_backupbuddy::$options['remote_destinations'][$destination_id]; // Update local var. - include( pb_backupbuddy::plugin_path() . '/destinations/live/_stats.php' ); // Recalculate stats. - //pb_backupbuddy::disalert( '', __( 'Live Database Backup paused.', 'it-l10n-backupbuddy' ) ); - $message = __( 'Live Database Backup paused.', 'it-l10n-backupbuddy' ); - } else if ( 'resume_continuous' == $action ) { - backupbuddy_api::setLiveStatus( $pause_continuous = false, $pause_periodic = '' ); - $destination = pb_backupbuddy::$options['remote_destinations'][$destination_id]; // Update local var. - include( pb_backupbuddy::plugin_path() . '/destinations/live/_stats.php' ); // Recalculate stats. - //pb_backupbuddy::disalert( '', __( 'Live Database Backup resumed.', 'it-l10n-backupbuddy' ) ); - $message = __( 'Live Database Backup resumed.', 'it-l10n-backupbuddy' ); - } else { - $error = 'Error #1000. Invalid request.'; - } - - return array( 'ok' => 1, '_error' => $error, '_message' => $message ); - } - - - - function download_troubleshooting() { - require( pb_backupbuddy::plugin_path() . '/destinations/live/_troubleshooting.php' ); - backupbuddy_live_troubleshooting::run(); - $output = "**File best viewed with wordwrap OFF**\n\n" . print_r( backupbuddy_live_troubleshooting::get_raw_results(), true ); - $backup_prefix = backupbuddy_core::backup_prefix(); - return array( 'output' => $output, 'backup_prefix' => $backup_prefix ); - } - - function get_live_backups() { - $destination_id = $_POST['destination_id']; - // Load required files. - require_once( pb_backupbuddy::plugin_path() . '/destinations/s32/init.php' ); - - if ( ! isset( pb_backupbuddy::$options['remote_destinations'][ $destination_id ] ) ) { - return array( 'error' => 'Error #9828332: Destination not found with id `' . htmlentities( $destination_id ) . '`.' ); - } - require_once( pb_backupbuddy::plugin_path() . '/destinations/stash2/init.php' ); - $settings = &pb_backupbuddy::$options['remote_destinations'][ $destination_id ]; - $settings = pb_backupbuddy_destination_stash2::_formatSettings( $settings ); - - $destination = pb_backupbuddy::$options['remote_destinations'][ $destination_id ]; - - if ( 'live' == $destination['type'] ) { - $remotePath = 'snapshot-';// . backupbuddy_core::backup_prefix(); - $site_only = true; - } else { - // Get list of files for this site. - $remotePath = 'backup-';// . backupbuddy_core::backup_prefix(); - $site_only = true; - } - - $files = pb_backupbuddy_destination_stash2::listFiles( $settings, '', $site_only ); //2nd param was $remotePath. - if ( ! is_array( $files ) ) { - return array( 'error' => 'Error #892329c: ' . $files ); - } - - $backup_list_temp = array(); - foreach( (array)$files as $file ) { - - if ( ( '' != $remotePath ) && ( ! backupbuddy_core::startsWith( basename( $file['filename'] ), $remotePath ) ) ) { // Only show backups for this site unless set to show all. - continue; - } - - $last_modified = $file['uploaded_timestamp']; - $size = (double) $file['size']; - $backup_type = backupbuddy_core::getBackupTypeFromFile( $file['filename'], $quiet = false, $skip_fileoptions = true ); - - // Generate array of table rows. - while( isset( $backup_list_temp[$last_modified] ) ) { // Avoid collisions. - $last_modified += 0.1; - } - - if ( 'live' == $destination['type'] ) { - $backup_list_temp[$last_modified] = array( - array( base64_encode( $file['url'] ), '' . pb_backupbuddy::$format->date( pb_backupbuddy::$format->localize_time( $last_modified ) ) . ' (' . pb_backupbuddy::$format->time_ago( $last_modified ) . ' ago)
' . basename( $file['filename'] ) . '' ), - pb_backupbuddy::$format->date( pb_backupbuddy::$format->localize_time( $last_modified ) ) . '
(' . pb_backupbuddy::$format->time_ago( $last_modified ) . ' ago)', - pb_backupbuddy::$format->file_size( $size ), - backupbuddy_core::pretty_backup_type( $backup_type ), - ); - } else { - $backup_list_temp[$last_modified] = array( - array( base64_encode( $file['url'] ), '' . basename( $file['filename'] ) . '' ), - pb_backupbuddy::$format->date( pb_backupbuddy::$format->localize_time( $last_modified ) ) . '
(' . pb_backupbuddy::$format->time_ago( $last_modified ) . ' ago)', - pb_backupbuddy::$format->file_size( $size ), - backupbuddy_core::pretty_backup_type( $backup_type ), - ); - } - - } - - krsort( $backup_list_temp ); - $backup_list = array(); - foreach( $backup_list_temp as $backup_item ) { - $backup_list[ $backup_item[0][0] ] = $backup_item; - } - unset( $backup_list_temp ); - - return array( 'backup_list' => $backup_list ); - } - - function copy_file_to_local() { - - $file = base64_decode( $_POST['cpy_file'] ); - $destination_id = $_POST['destination_id']; - - // Load required files. - require_once( pb_backupbuddy::plugin_path() . '/destinations/s32/init.php' ); - if ( ! isset( pb_backupbuddy::$options['remote_destinations'][ $destination_id ] ) ) { - return array( 'error' => 'Error #9828332: Destination not found with id `' . htmlentities( $destination_id ) . '`.' ); - } - - $settings = &pb_backupbuddy::$options['remote_destinations'][ $destination_id ]; - $settings = pb_backupbuddy_destination_stash2::_formatSettings( $settings ); - - pb_backupbuddy::status( 'details', 'Scheduling Cron for creating Stash copy.' ); - backupbuddy_core::schedule_single_event( time(), 'process_remote_copy', array( 'stash2', $file, $settings ) ); - if ( '1' != pb_backupbuddy::$options['skip_spawn_cron_call'] ) { - update_option( '_transient_doing_cron', 0 ); // Prevent cron-blocking for next item. - spawn_cron( time() + 150 ); // Adds > 60 seconds to get around once per minute cron running limit. - } - return array( 'ok' => 1 ); - - } - - function delete_file_backup() { - // Handle deletion. - $files = $_POST['items']; - $destination_id = $_POST['destination_id']; - - // Load required files. - require_once( pb_backupbuddy::plugin_path() . '/destinations/s32/init.php' ); - if ( ! isset( pb_backupbuddy::$options['remote_destinations'][ $destination_id ] ) ) { - return array( 'error' => 'Error #9828332: Destination not found with id `' . htmlentities( $destination_id ) . '`.' ); - } - - $settings = &pb_backupbuddy::$options['remote_destinations'][ $destination_id ]; - $settings = pb_backupbuddy_destination_stash2::_formatSettings( $settings ); - - $deleteFiles = array(); - foreach( (array)$files as $file ) { - $file = base64_decode( $file ); - - $startPos = pb_backupbuddy_destination_stash2::strrpos_count( $file, '/', 2 ) + 1; // next to last slash. - $file = substr( $file, $startPos ); - if ( FALSE !== strstr( $file, '?' ) ) { - $file = substr( $file, 0, strpos( $file, '?' ) ); - } - $deleteFiles[] = $file; - } - $response = pb_backupbuddy_destination_stash2::deleteFiles( $settings, $deleteFiles ); - - if ( true === $response ) { - $msg = 'Deleted ' . implode( ', ', $deleteFiles ) . '.'; - } else { - $msg = 'Failed to delete one or more files. Details: `' . $response . '`.'; - } - - return array( 'ok' => 1, 'msg' => $msg ); - } - - function get_live_stats() { - - // Check if running PHP 5.3+. - $php_minimum = 5.3; - if ( version_compare( PHP_VERSION, $php_minimum, '<' ) ) { // Server's PHP is insufficient. - return array('error' => '-1'); - } - - if ( false === ( $stats = backupbuddy_api::getLiveStats() ) ) { // Live is disconnected. - return array('error' => '-1'); - } - - // If there is more to do and too long of time has passed since activity then try to jumpstart the process at the beginning. - if ( ( ( 0 == $stats['files_total'] ) || ( $stats['files_sent'] < $stats['files_total'] ) ) && ( 'wait_on_transfers' != $stats['current_function'] ) ) { // ( Files to send not yet calculated OR more remain to send ) AND not on the wait_on_transfers step. - $time_since_last_activity = microtime( true ) - $stats['last_periodic_activity']; - - if ( $time_since_last_activity < 30 ) { // Don't even bother getting max execution time if it's been less than 30 seconds since run. - // do nothing - } else { // More than 30 seconds since last activity. - - // Detect max PHP execution time. If TESTED value is higher than PHP value then go with that since we want to err on not overlapping processes here. - $detected_execution = backupbuddy_core::detectLikelyHighestExecutionTime(); - - if ( $time_since_last_activity > ( $detected_execution + backupbuddy_constants::TIMED_OUT_PROCESS_RESUME_WIGGLE_ROOM ) ) { // Enough time has passed to assume timed out. - - require_once( pb_backupbuddy::plugin_path() . '/destinations/live/live.php' ); - if ( false === ( $liveID = backupbuddy_live::getLiveID() ) ) { - die( '-1' ); - } - if ( '1' != pb_backupbuddy::$options['remote_destinations'][ $liveID ]['pause_periodic'] ) { // Only proceed if NOT paused. - - pb_backupbuddy::status( 'warning', 'BackupBuddy Stash Live process appears timed out while user it viewing Live page. Forcing run now.' ); - - $cronArgs = array(); - $schedule_result = backupbuddy_core::schedule_single_event( time(), 'live_periodic', $cronArgs ); - if ( true === $schedule_result ) { - pb_backupbuddy::status( 'details', 'Next Live Periodic chunk step cron event scheduled.' ); - } else { - pb_backupbuddy::status( 'error', 'Next Live Periodic chunk step cron event FAILED to be scheduled.' ); - } - if ( '1' != pb_backupbuddy::$options['skip_spawn_cron_call'] ) { - pb_backupbuddy::status( 'details', 'Spawning cron now.' ); - update_option( '_transient_doing_cron', 0 ); // Prevent cron-blocking for next item. - spawn_cron( time() + 150 ); // Adds > 60 seconds to get around once per minute cron running limit. - } - } - - } - } - - } - - return array('result' => json_encode( $stats )); - } - - function save_license_settings() { - $settings = $_POST['settings']; - if (is_array($settings) && isset($GLOBALS['ithemes-updater-settings'])) { - $GLOBALS['ithemes-updater-settings']->update_options( $settings ); - return array('ok' => 1); - } - return false; - } - - function load_products_license() { - $packages = array(); - $packages_name = array(); - if (isset($GLOBALS['ithemes_updater_path'])) { - - require_once( $GLOBALS['ithemes_updater_path'] . '/functions.php' ); - require_once( $GLOBALS['ithemes_updater_path'] . '/api.php' ); - require_once( $GLOBALS['ithemes_updater_path'] . '/keys.php' ); - - require_once( $GLOBALS['ithemes_updater_path'] . '/packages.php' ); - - $details = Ithemes_Updater_Packages::get_full_details(); - $packages = isset($details['packages']) ? $details['packages'] : array(); - if (is_array($packages)) { - foreach ( $packages as $path => $data ) { - $packages_name[$path] = Ithemes_Updater_Functions::get_package_name( $data['package'] ); - } - } - - } - return array('ok' => 1, 'packages' => $packages, 'packages_name' => $packages_name); - } - - function activate_package() { - - $username = $_POST['username']; - $password = $_POST['password']; - $packages = $_POST['packages']; - - $return = array( 'ok' => 1 ); - if (isset($GLOBALS['ithemes_updater_path'])) { - - require_once( $GLOBALS['ithemes_updater_path'] . '/functions.php' ); - require_once( $GLOBALS['ithemes_updater_path'] . '/api.php' ); - require_once( $GLOBALS['ithemes_updater_path'] . '/keys.php' ); - - require_once( $GLOBALS['ithemes_updater_path'] . '/packages.php' ); - - - $response = Ithemes_Updater_API::activate_package( $username, $password, $packages ); - - if ( is_wp_error( $response ) ) { - $errors[] = $this->get_error_explanation( $response ); - $return['errors'] = $errors; - return $return; + if ( !strstr( pb_backupbuddy::_GET( 'backupbuddy_backup' ), backupbuddy_core::backup_prefix() ) ) { + die( 'Access Denied. You may only download backups specific to your Multisite Subsite. Only Network Admins may download backups for another subsite in the network.' ); + } } - - if ( empty( $response['packages'] ) ) { - $errors[] = __( 'An unknown server error occurred. Please try to license your products again at another time.', 'it-l10n-backupbuddy' ); - $return['errors'] = $errors; - return $return; + + if ( !file_exists( backupbuddy_core::getBackupDirectory() . pb_backupbuddy::_GET( 'backupbuddy_backup' ) ) ) { // Does not exist. + die( 'Error #548957857584784332. The requested backup file does not exist. It may have already been deleted.' ); } - - uksort( $response['packages'], 'strnatcasecmp' ); - - $success = array(); - $warn = array(); - $fail = array(); - - foreach ( $response['packages'] as $package => $data ) { - if ( preg_match( '/ \|\|\| \d+$/', $package ) ) - continue; - - $name = Ithemes_Updater_Functions::get_package_name( $package ); - - if ( ! empty( $data['key'] ) ) - $success[] = $name; - else if ( ! empty( $data['status'] ) && ( 'expired' == $data['status'] ) ) - $warn[$name] = __( 'Your product subscription has expired', 'it-l10n-backupbuddy' ); - else - $fail[$name] = $data['error']['message']; + + $abspath = str_replace( '\\', '/', ABSPATH ); + $backup_dir = str_replace( '\\', '/', backupbuddy_core::getBackupDirectory() ); + + if ( FALSE === stristr( $backup_dir, $abspath ) ) { + die( 'Error #5432532. You cannot download backups stored outside of the WordPress web root. Please use FTP or other means.' ); } - - - if ( ! empty( $success ) ) { - $messages[] = wp_sprintf( __( 'Successfully licensed %l.', 'it-l10n-backupbuddy' ), $success ); - $return['messages'] = $messages; - } - - if ( ! empty( $fail ) ) { - foreach ( $fail as $name => $reason ) - $errors[] = sprintf( __( 'Unable to license %1$s. Reason: %2$s', 'it-l10n-backupbuddy' ), $name, $reason ); - $return['errors'] = $errors; + + $sitepath = str_replace( $abspath, '', $backup_dir ); + $download_url = rtrim( site_url(), '/\\' ) . '/' . trim( $sitepath, '/\\' ) . '/' . pb_backupbuddy::_GET( 'backupbuddy_backup' ); + + if ( pb_backupbuddy::$options['lock_archives_directory'] == '1' ) { + + if ( file_exists( backupbuddy_core::getBackupDirectory() . '.htaccess' ) ) { + $unlink_status = @unlink( backupbuddy_core::getBackupDirectory() . '.htaccess' ); + if ( $unlink_status === false ) { + die( 'Error #844594. Unable to temporarily remove .htaccess security protection on archives directory to allow downloading. Please verify permissions of the BackupBuddy archives directory or manually download via FTP.' ); + } + } + + header( 'Location: ' . $download_url ); + ob_clean(); + flush(); + sleep( 8 ); + + $htaccess_creation_status = @file_put_contents( backupbuddy_core::getBackupDirectory() . '.htaccess', 'deny from all' ); + if ( $htaccess_creation_status === false ) { + die( 'Error #344894545. Security Warning! Unable to create security file (.htaccess) in backups archive directory. This file prevents unauthorized downloading of backups should someone be able to guess the backup location and filenames. This is unlikely but for best security should be in place. Please verify permissions on the backups directory.' ); + } + + } else { + header( 'Location: ' . $download_url ); } - - if ( ! empty( $warn ) ) { - foreach ( $warn as $name => $reason ) - $soft_errors[] = sprintf( __( 'Unable to license %1$s. Reason: %2$s', 'it-l10n-backupbuddy' ), $name, $reason ); - $return['soft_errors'] = $soft_errors; - } - - } - return $return; - } - - function deactivate_package( $data ) { - - $username = $_POST['username']; - $password = $_POST['password']; - $packages = $_POST['packages']; - - $return = array( 'ok' => 1 ); - - if (isset($GLOBALS['ithemes_updater_path'])) { - - require_once( $GLOBALS['ithemes_updater_path'] . '/functions.php' ); - require_once( $GLOBALS['ithemes_updater_path'] . '/api.php' ); - require_once( $GLOBALS['ithemes_updater_path'] . '/keys.php' ); - - require_once( $GLOBALS['ithemes_updater_path'] . '/packages.php' ); - - $response = Ithemes_Updater_API::deactivate_package($username, $password, $packages ); - - if ( is_wp_error( $response ) ) { - $errors[] = $this->get_error_explanation( $response ); - $return['errors'] = $errors; - return $return; - } - - if ( empty( $response['packages'] ) ) { - $errors[] = __( 'An unknown server error occurred. Please try to remove licenses from your products again at another time.', 'it-l10n-mainwp-backupbuddy' ); - $return['errors'] = $errors; - return $return; - } - - - uksort( $response['packages'], 'strnatcasecmp' ); - - $success = array(); - $fail = array(); - - foreach ( $response['packages'] as $package => $data ) { - if ( preg_match( '/ \|\|\| \d+$/', $package ) ) - continue; - - $name = Ithemes_Updater_Functions::get_package_name( $package ); - - if ( isset( $data['status'] ) && ( 'inactive' == $data['status'] ) ) - $success[] = $name; - else if ( isset( $data['error'] ) && isset( $data['error']['message'] ) ) - $fail[$name] = $data['error']['message']; - else - $fail[$name] = __( 'Unknown server error.', 'it-l10n-mainwp-backupbuddy' ); - } - - - if ( ! empty( $success ) ) { - $messages[] = wp_sprintf( _n( 'Successfully removed license from %l.', 'Successfully removed licenses from %l.', count( $success ), 'it-l10n-mainwp-backupbuddy' ), $success ); - $return['messages'] = $messages; - } - - if ( ! empty( $fail ) ) { - foreach ( $fail as $name => $reason ) - $errors[] = sprintf( __( 'Unable to remove license from %1$s. Reason: %2$s', 'it-l10n-mainwp-backupbuddy' ), $name, $reason ); - $return['errors'] = $errors; - - } - - } - return $return; + die(); } - - private function get_error_explanation( $error, $package = '' ) { + + function create_backup() { + $requested_profile = $_POST['profile_id']; + + if (!isset(pb_backupbuddy::$options['profiles'][ $requested_profile ])) { + return array('error' => 'Invalid Profile. Not found.'); + } + + require_once( pb_backupbuddy::plugin_path() . '/classes/backup.php' ); + $newBackup = new pb_backupbuddy_backup(); + + $profile_array = pb_backupbuddy::$options['profiles'][ $requested_profile ]; + $serial_override = pb_backupbuddy::random_string( 10 ); + + if ( $newBackup->start_backup_process( + $profile_array, + 'manual', // trigger + array(), + isset($_POST['post_backup_steps']) && is_array($_POST['post_backup_steps']) ? $_POST['post_backup_steps'] : array(), + '', + $serial_override, + '', // export_plugins + '', // direction + '' // deployDestination + ) !== true ) { + return array('error' => __('Fatal Error #4344443: Backup failure. Please see any errors listed in the Status Log for details.', 'it-l10n-backupbuddy' )); + } + return array('result' => 'SUCCESS'); + } + + function start_backup() { + require_once( pb_backupbuddy::plugin_path() . '/classes/backup.php' ); + $newBackup = new pb_backupbuddy_backup(); + $data = $_POST['data']; + if (is_array($data) && isset($data['serial_override'])) { + if ( $newBackup->start_backup_process( + $data['profile_array'], + $data['trigger'], + array(), + isset($data['post_backup_steps']) && is_array($data['post_backup_steps']) ? $data['post_backup_steps'] : array(), + '', + $data['serial_override'], + isset($data['export_plugins']) ? $data['export_plugins'] : '', + $data['direction'], + isset($data['deployDestination']) ? $data['deployDestination'] : '' + ) !== true ) { + return array('error' => __('Fatal Error #4344443: Backup failure. Please see any errors listed in the Status Log for details.', 'it-l10n-backupbuddy' )); + } + } else { + return array('error' => 'Invalid backup request.'); + } + + return array('ok' => 1); + + } + + function backup_status() { + $data = $_POST['data']; + $result = ''; + if (is_array($data) && isset($data['serial'])) { + ob_start(); + backupbuddy_api::getBackupStatus( $data['serial'], $data['specialAction'], $data['initwaitretrycount'], $data['sqlFile'], $echo = true ); + $result = ob_get_clean(); + } else { + return array('error' => 'Invalid backup request.'); + } + return array('ok' => 1, 'result' => $result); + } + + function stop_backup() { + $serial = $_POST['serial']; + set_transient( 'pb_backupbuddy_stop_backup-' . $serial, true, ( 60*60*24 ) ); + return array('ok' => 1); + } + + function remote_save() { + $data = isset($_POST['data']) ? $_POST['data'] : false; + $destination_id = isset($_POST['destination_id']) ? $_POST['destination_id'] : 0; + if (is_array($data)) { + if (isset(pb_backupbuddy::$options['remote_destinations'][$destination_id])) { // update + pb_backupbuddy::$options['remote_destinations'][$destination_id] = array_merge( pb_backupbuddy::$options['remote_destinations'][$destination_id], $data ); + } else { // add new + $data['token'] = pb_backupbuddy::$options['dropboxtemptoken']; + pb_backupbuddy::$options['remote_destinations'][$destination_id] = $data; + } + pb_backupbuddy::save(); + return array('ok' => 1); + } else { + return array('error' => 'Invalid request.'); + } + } + + function remote_list() { + $information = array(); + if (isset(pb_backupbuddy::$options['remote_destinations'])) { // update + $information['remote_destinations'] = pb_backupbuddy::$options['remote_destinations']; + } + $information['result'] = 'SUCCESS'; + return $information; + } + + function remote_delete() { + $destination_id = isset($_POST['destination_id']) ? $_POST['destination_id'] : null; + if ($destination_id !== null) { + require_once( pb_backupbuddy::plugin_path() . '/destinations/bootstrap.php' ); + $delete_response = pb_backupbuddy_destinations::delete_destination( $destination_id, true ); + + if ( $delete_response !== true ) { + return array('error' => $delete_response); + } else { + return array('ok' => 1); + } + } else { + return array('error' => 'Invalid request.'); + } + } + + function remote_send() { + + $destination_id = isset($_POST['destination_id']) ? $_POST['destination_id'] : null; + $file = isset($_POST['file']) ? $_POST['file'] : null; + $trigger = isset($_POST['trigger']) ? $_POST['trigger'] : 'manual'; + + if ( $file != 'importbuddy.php' ) { + $backup_file = backupbuddy_core::getBackupDirectory() . $file; + if ( ! file_exists( $backup_file ) ) { // Error if file to send did not exist! + $error_message = 'Unable to find file `' . $backup_file . '` to send. File does not appear to exist. You can try again in a moment or turn on full error logging and try again to log for support.'; + pb_backupbuddy::status( 'error', $error_message ); + return array( 'error' => $error_message); + } + if ( is_dir( $backup_file ) ) { // Error if a directory is trying to be sent. + $error_message = 'You are attempting to send a directory, `' . $backup_file . '`. Try again and verify there were no javascript errors.'; + pb_backupbuddy::status( 'error', $error_message ); + return array( 'error' => $error_message); + } + } else { + $backup_file = ''; + } + + if ( isset($_POST['send_importbuddy']) && $_POST['send_importbuddy'] == '1' ) { + $send_importbuddy = true; + pb_backupbuddy::status( 'details', 'Cron send to be scheduled with importbuddy sending.' ); + } else { + $send_importbuddy = false; + pb_backupbuddy::status( 'details', 'Cron send to be scheduled WITHOUT importbuddy sending.' ); + } + + if ( isset($_POST['delete_after']) && $_POST['delete_after'] == '1' ) { + $delete_after = true; + pb_backupbuddy::status( 'details', 'Remote send set to delete after successful send.' ); + } else { + $delete_after = false; + pb_backupbuddy::status( 'details', 'Remote send NOT set to delete after successful send.' ); + } + + if ( !isset( pb_backupbuddy::$options['remote_destinations'][$destination_id] ) ) { + return array( 'error' => 'Error #833383: Invalid destination ID `' . htmlentities( $destination_id ) . '`.' ); + } + + + // For Stash we will check the quota prior to initiating send. + if ( pb_backupbuddy::$options['remote_destinations'][$destination_id]['type'] == 'stash' ) { + // Pass off to destination handler. + require_once( pb_backupbuddy::plugin_path() . '/destinations/bootstrap.php' ); + $send_result = pb_backupbuddy_destinations::get_info( 'stash' ); // Used to kick the Stash destination into life. + $stash_quota = pb_backupbuddy_destination_stash::get_quota( pb_backupbuddy::$options['remote_destinations'][$destination_id], true ); + + if ( isset( $stash_quota['error'] ) ) { + return array( 'error' => ' Error accessing Stash account. Send aborted. Details: `' . implode( ' - ', $stash_quota['error'] ) . '`.'); + } + + if ( $backup_file != '' ) { + $backup_file_size = filesize( $backup_file ); + } else { + $backup_file_size = 50000; + } + if ( ( $backup_file_size + $stash_quota['quota_used'] ) > $stash_quota['quota_total'] ) { + ob_start(); + echo "You do not have enough Stash storage space to send this file. Please upgrade your Stash storage or delete files to make space.\n\n"; + echo 'Attempting to send file of size ' . pb_backupbuddy::$format->file_size( $backup_file_size ) . ' but you only have ' . $stash_quota['quota_available_nice'] . ' available. '; + echo 'Currently using ' . $stash_quota['quota_used_nice'] . ' of ' . $stash_quota['quota_total_nice'] . ' (' . $stash_quota['quota_used_percent'] . '%).'; + $error = ob_get_clean(); + return array( 'error' => $error ); + } else { + if ( isset( $stash_quota['quota_warning'] ) && ( $stash_quota['quota_warning'] != '' ) ) { + $warning = 'Warning: ' . $stash_quota['quota_warning'] . "\n\n"; + $success_output = true; + } + } + + } // end if Stash. + + pb_backupbuddy::status( 'details', 'Scheduling cron to send to this remote destination...' ); + + $schedule_result = backupbuddy_core::schedule_single_event( time(), 'remote_send', array( $destination_id, $backup_file, $trigger, $send_importbuddy, $delete_after ) ); + if ( $schedule_result === FALSE ) { + $error = 'Error scheduling file transfer. Please check your BackupBuddy error log for details. A plugin may have prevented scheduling or the database rejected it.'; + pb_backupbuddy::status( 'error', $error ); + return array( 'error' => $error); + } else { + pb_backupbuddy::status( 'details', 'Cron to send to remote destination scheduled.' ); + } + if ( '1' != pb_backupbuddy::$options['skip_spawn_cron_call'] ) { + update_option( '_transient_doing_cron', 0 ); // Prevent cron-blocking for next item. + spawn_cron( time() + 150 ); // Adds > 60 seconds to get around once per minute cron running limit. + } + return array( 'ok' => 1); + } + + function get_main_log() { + $log_file = backupbuddy_core::getLogDirectory() . 'log-' . pb_backupbuddy::$options['log_serial'] . '.txt'; + ob_start(); + if ( file_exists( $log_file ) ) { + readfile( $log_file ); + } else { + echo __('Nothing has been logged.', 'it-l10n-backupbuddy' ); + } + $result = ob_get_clean(); + return array('result' => $result ); + } + + function settings_other() { + + $other_action = $_POST['other_action']; + + $message = ''; + $error = ''; + + if ( 'cleanup_now' == $other_action ) { + $message = 'Performing cleanup procedures now trimming old files and data.'; + require_once( pb_backupbuddy::plugin_path() . '/classes/housekeeping.php' ); + backupbuddy_housekeeping::run_periodic( 0 ); // 0 cleans up everything even if not very old. + + } else if ( 'delete_tempfiles_now' == $other_action) { + $tempDir = backupbuddy_core::getTempDirectory(); + $logDir = backupbuddy_core::getLogDirectory(); + $message = 'Deleting all files contained within `' . $tempDir . '` and `' . $logDir . '`.' ; + pb_backupbuddy::$filesystem->unlink_recursive( $tempDir ); + pb_backupbuddy::$filesystem->unlink_recursive( $logDir ); + pb_backupbuddy::anti_directory_browsing( $logDir, $die = false ); // Put log dir back in place. + } else if ( 'reset_log' == $other_action ) { + $log_file = backupbuddy_core::getLogDirectory() . 'log-' . pb_backupbuddy::$options['log_serial'] . '.txt'; + if ( file_exists( $log_file ) ) { + @unlink( $log_file ); + } + if ( file_exists( $log_file ) ) { // Didnt unlink. + $error = 'Unable to clear log file. Please verify permissions on file `' . $log_file . '`.'; + } else { // Unlinked. + $message = 'Cleared log file.'; + } + } else if ( 'reset_disalerts' == $other_action) { + pb_backupbuddy::$options['disalerts'] = array(); + pb_backupbuddy::save(); + $message = 'Dismissed alerts have been reset. They may now be visible again.'; + + } else if ( 'cancel_running_backups' == $other_action) { + require_once( pb_backupbuddy::plugin_path() . '/classes/fileoptions.php' ); + + $fileoptions_directory = backupbuddy_core::getLogDirectory() . 'fileoptions/'; + $files = glob( $fileoptions_directory . '*.txt' ); + if ( ! is_array( $files ) ) { + $files = array(); + } + $cancelCount = 0; + for ($x = 0; $x <= 3; $x++) { // Try this a few times since there may be race conditions on an open file. + foreach( $files as $file ) { + pb_backupbuddy::status( 'details', 'Fileoptions instance #383.' ); + + $backup_options = new pb_backupbuddy_fileoptions( $file, $read_only = false ); + if ( true !== ( $result = $backup_options->is_ok() ) ) { + pb_backupbuddy::status( 'error', 'Error retrieving fileoptions file `' . $file . '`. Err 335353266.' ); + } else { + if ( empty( $backup_options->options['finish_time'] ) || ( ( FALSE !== $backup_options->options['finish_time'] ) && ( '-1' != $backup_options->options['finish_time'] ) ) ) { + $backup_options->options['finish_time'] = -1; // Force marked as cancelled by user. + $backup_options->save(); + $cancelCount++; + } + } + } + sleep( 1 ); + } + + $message = 'Marked all timed out or running backups & transfers as officially cancelled (`' . $cancelCount . '` total found).'; + } + + return array('_error' => $error, '_message' => $message); + } + + function malware_scan() { + + backupbuddy_core::schedule_single_event( time(), 'housekeeping', array() ); + update_option( '_transient_doing_cron', 0 ); + spawn_cron( time() + 150 ); + + ob_start(); + + if ( ! defined( 'pluginbuddy_importbuddy' ) ) { + $url = home_url(); + } else { + $url = str_replace( $_SERVER['QUERY_STRING'], '', $_SERVER['REQUEST_URI'] ); + $url = str_replace( basename( $url ) , '', $url ); + $url = 'http://' . $_SERVER['HTTP_HOST'] . $url; + } + ?> + + + + start_metabox( __( 'Malware Scan URL', 'it-l10n-backupbuddy' ), true, 'width: 100%;' ); + + ?> + + + + Scanning `' . $url . '`.

'; + if ( !defined( 'pluginbuddy_importbuddy' ) ) { + $scan = get_transient( 'pb_backupbuddy_malwarescan' ); + } else { + $scan = false; + } + + if ( false === $scan ) { + flush(); + + $scan = wp_remote_get( + 'http://sitecheck.sucuri.net/scanner/?scan=' . urlencode( $url ) . '&serialized&clear=true', + array( + 'method' => 'GET', + 'timeout' => 45, + 'redirection' => 5, + 'httpversion' => '1.0', + 'blocking' => true, + 'headers' => array(), + 'body' => null, + 'cookies' => array() + ) + ); + + if ( is_wp_error( $scan ) ) { + pb_backupbuddy::alert( __('ERROR #24452. Unable to load Malware Scan results. Details:', 'it-l10n-backupbuddy' ). ' ' . $scan->get_error_message(), true ); + $scan = 'N;'; + } else { + $scan = $scan['body']; + set_transient( 'pb_backupbuddy_malwarescan', $scan, 60*60*1 ); // 1 hour cache. + } + + } + + $continue_2 = true; + if ( substr( $scan, 0, 2 ) == 'N;' ) { + echo __('An error was encountered attempting to scan this site.','it-l10n-backupbuddy' ), '
'; + echo __('An internet connection is required and this site must be accessible on the public internet.', 'it-l10n-backupbuddy' ); + echo '
'; + $scan = array(); + $continue_2 = false; + } else { + $scan = maybe_unserialize( $scan ); + //echo '
';
+				//print_r( $scan );
+				//echo '
'; + } + + } + + pb_backupbuddy::$ui->end_metabox(); + ?> + + + + $array_item ) { + if ( is_array( $array_item ) ) { + $array[$array_key] = lined_array( $array_item ); + } + } + //return implode( '
', $array ); + $return = ''; + foreach( $array as $array_item ) { + $return .= $array_item . '
'; + } + return $return; + } else { + if ( empty( $array ) ) { + return ''.__('none', 'it-l10n-backupbuddy' ).'
'; + } else { + return $array . '
'; + } + } + } + + if ( !empty( $scan['MALWARE'] ) && ( $scan['MALWARE'] != 'E' ) ) { + echo '

', __('Warning: Possible Malware Detected!', 'it-l10n-backupbuddy' ), '

',__('See details below.', 'it-l10n-backupbuddy' ), '
'; + } + + ?> + + +
+
+
+ + + + + + + + + + + + + + + + + +
+
+
+ $result); + } + + + function live_setup() { + + $errors = array(); + + $archive_types = array( + 'db' => __( 'Database Backup', 'it-l10n-backupbuddy' ), + 'full' => __( 'Full Backup', 'it-l10n-backupbuddy' ), + 'plugins' => __( 'Plugins Backup', 'it-l10n-backupbuddy' ), + 'themes' => __( 'Themes Backup', 'it-l10n-backupbuddy' ), + ); + + $archive_periods = array( + 'daily', + 'weekly', + 'monthly', + 'yearly', + ); + + + if ( ( '' == $_POST['live_username'] ) || ( '' == $_POST['live_password'] ) ) { // A field is blank. + $errors[] = 'You must enter your iThemes username & password to log in to BackupBuddy Stash Live.'; + } else { // Username and password provided. + + require_once( pb_backupbuddy::plugin_path() . '/destinations/stash2/class.itx_helper2.php' ); + require_once( pb_backupbuddy::plugin_path() . '/destinations/stash2/init.php' ); + require_once( pb_backupbuddy::plugin_path() . '/destinations/live/init.php' ); + global $wp_version; + + $itxapi_username = strtolower( $_POST['live_username'] ); + $password_hash = iThemes_Credentials::get_password_hash( $itxapi_username, $_POST['live_password'] ); + $access_token = ITXAPI_Helper2::get_access_token( $itxapi_username, $password_hash, site_url(), $wp_version ); + + $settings = array( + 'itxapi_username' => $itxapi_username, + 'itxapi_password' => $access_token, + ); + $response = pb_backupbuddy_destination_stash2::stashAPI( $settings, 'connect' ); + + if ( ! is_array( $response ) ) { // Error message. + $errors[] = print_r( $response, true ); + } else { + if ( isset( $response['error'] ) ) { + $errors[] = $response['error']['message']; + } else { + if ( isset( $response['token'] ) ) { + $itxapi_token = $response['token']; + } else { + $errors[] = 'Error #2308832: Unexpected server response. Token missing. Check your BackupBuddy Stash Live login and try again. Detailed response: `' . print_r( $response, true ) .'`.'; + } + } + } + + // If we have the token then create the Live destination. + if ( isset( $itxapi_token ) ) { + if ( count( pb_backupbuddy::$options['remote_destinations'] ) > 0 ) { + $nextDestKey = max( array_keys( pb_backupbuddy::$options['remote_destinations'] ) ) + 1; + } else { // no destinations yet. first index. + $nextDestKey = 0; + } + + pb_backupbuddy::$options['remote_destinations'][ $nextDestKey ] = pb_backupbuddy_destination_live::$default_settings; + pb_backupbuddy::$options['remote_destinations'][ $nextDestKey ]['itxapi_username'] = $_POST['live_username']; + pb_backupbuddy::$options['remote_destinations'][ $nextDestKey ]['itxapi_token'] = $itxapi_token; + pb_backupbuddy::$options['remote_destinations'][ $nextDestKey ]['title'] = 'My BackupBuddy Stash Live'; + + // Notification email. + pb_backupbuddy::$options['remote_destinations'][ $nextDestKey ]['email'] = $_POST['email']; + + // Archive limits. + foreach( $archive_types as $archive_type => $archive_type_name ) { + foreach( $archive_periods as $archive_period ) { + $settings_name = 'limit_' . $archive_type . '_' . $archive_period; + pb_backupbuddy::$options['remote_destinations'][ $nextDestKey ][ $settings_name ] = $_POST['live_settings'][$settings_name]; + } + } + + if ( '1' == $_POST['send_snapshot_notification'] ) { + pb_backupbuddy::$options['remote_destinations'][ $nextDestKey ]['send_snapshot_notification'] = $_POST['send_snapshot_notification']; + } else { + pb_backupbuddy::$options['remote_destinations'][ $nextDestKey ]['send_snapshot_notification'] = '0'; + } + + pb_backupbuddy::save(); + $destination_id = $nextDestKey; + + // Send new settings for archive limiting to Stash API. + backupbuddy_live::send_trim_settings(); + + + + // Set first run of BackupBuddy Stash Live so it begins immediately. + $cronArgs = array(); + $schedule_result = backupbuddy_core::schedule_single_event( time(), 'live_periodic', $cronArgs ); + if ( true === $schedule_result ) { + pb_backupbuddy::status( 'details', 'Next Live Periodic chunk step cron event scheduled.' ); + } else { + pb_backupbuddy::status( 'error', 'Next Live Periodic chunk step cron event FAILED to be scheduled.' ); + } + if ( '1' != pb_backupbuddy::$options['skip_spawn_cron_call'] ) { + pb_backupbuddy::status( 'details', 'Spawning cron now.' ); + update_option( '_transient_doing_cron', 0 ); // Prevent cron-blocking for next item. + spawn_cron( time() + 150 ); // Adds > 60 seconds to get around once per minute cron running limit. + } + + } + + } // end if user and pass set. + + + if ( 0 == count( $errors ) ) { + pb_backupbuddy::save(); + $data = pb_backupbuddy::$options['remote_destinations'][ $destination_id ]; + return array( 'destination_id' => $destination_id, 'data' => $data); + } else { + return array( 'errors' => $errors ); + } + + } + + function live_save_settings() { + $data = $_POST['data']; + $new_destination_id = $_POST['destination_id']; + + + require_once( pb_backupbuddy::plugin_path() . '/destinations/bootstrap.php' ); + require_once( pb_backupbuddy::plugin_path() . '/destinations/live/live.php' ); + require_once( pb_backupbuddy::plugin_path() . '/destinations/live/live_periodic.php' ); + + $destination_id = backupbuddy_live::getLiveID(); + $destination_settings = isset(pb_backupbuddy::$options['remote_destinations'][$destination_id]) ? pb_backupbuddy::$options['remote_destinations'][$destination_id] : array(); + + $check_current = !empty($destination_settings) ? true : false; + + $error = ''; + if ( $new_destination_id && is_array($data) ) { + $itxapi_username = isset($destination_settings['itxapi_username']) ? $destination_settings['itxapi_username'] : ''; + $itxapi_token = isset($destination_settings['itxapi_token']) ? $destination_settings['itxapi_token'] : ''; + $destination_settings = array_merge( $destination_settings, $data ); + $destination_settings['itxapi_username'] = $itxapi_username; + $destination_settings['itxapi_token'] = $itxapi_token; + pb_backupbuddy::$options['remote_destinations'][$new_destination_id] = $destination_settings; + + if ($check_current && $destination_id != $new_destination_id) { + unset(pb_backupbuddy::$options['remote_destinations'][$destination_id]); + } + + pb_backupbuddy::save(); + //pb_backupbuddy::alert( __( 'Settings saved. Restarting Live process so they take immediate effect.', 'it-l10n-backupbuddy' ) ); + set_transient( 'backupbuddy_live_jump', array( 'daily_init', array() ), 60*60*48 ); // Tells Live process to restart from the beginning (if mid-process) so new settigns apply. + + backupbuddy_live::send_trim_settings(); + return array('ok' => 1); + } else { + $error = 'Invalid data.'; + } + return array('error' => $error); + } + + function live_action_disconnect() { + $error = ''; + $liveDestinationID = $_POST['destination_id']; + + $return = array(); + if ($liveDestinationID) { + if (isset(pb_backupbuddy::$options['remote_destinations'][ $liveDestinationID ])) { + // Clear destination settings. + unset( pb_backupbuddy::$options['remote_destinations'][ $liveDestinationID ] ); + pb_backupbuddy::save(); + // Clear cached Live credentials. + require_once( pb_backupbuddy::plugin_path() . '/destinations/live/init.php' ); + delete_transient( pb_backupbuddy_destination_live::LIVE_ACTION_TRANSIENT_NAME ); + } else { + $error = 'Error: Not found.'; + } + $return['ok'] = 1; + } else { + $error = 'Error: Empty destination id.'; + } + + if (!empty($error)) + $return['error'] = $error; + + return $return; + } + + function live_action() { + $action = $_POST['live_action']; + $error = $message = ''; + + require_once( pb_backupbuddy::plugin_path() . '/destinations/live/live_periodic.php' ); + $state = backupbuddy_live_periodic::get_stats(); + + $destination_id = backupbuddy_live::getLiveID(); + $destination = backupbuddy_live_periodic::get_destination_settings(); + + if ( 'clear_log' == $action ) { + $sumLogFile = backupbuddy_core::getLogDirectory() . 'status-live_periodic_' . pb_backupbuddy::$options['log_serial'] . '.txt'; + @unlink( $sumLogFile ); + if ( file_exists( $sumLogFile ) ) { + $error = 'Error #893489322: Unable to clear log file `' . $sumLogFile . '`. Check permissions or manually delete.' ; + } else { + $message = 'Log file cleared.'; + } + + } else if ( 'create_snapshot' == $action ) { // < 100% backed up _OR_ ( we are on a step other than daily_init and the last_activity is more recent than the php runtime ) + if ( true === backupbuddy_api::runLiveSnapshot() ) { + //pb_backupbuddy::alert( '

' . __( 'Verifying everything is up to date before Snapshot', 'it-l10n-backupbuddy' ) . '

' . __( 'Please wait while we verify your backup is completely up to date before we create the Snapshot. This may take a few minutes...', 'it-l10n-backupbuddy' ) . '

', false, '', 'backupbuddy_live_snapshot_verify_uptodate' ); + $message = '

' . __( 'Verifying everything is up to date before Snapshot', 'it-l10n-backupbuddy' ) . '

' . __( 'Please wait while we verify your backup is completely up to date before we create the Snapshot. This may take a few minutes...', 'it-l10n-backupbuddy' ) . '

'; + require( pb_backupbuddy::plugin_path() . '/destinations/live/_manual_snapshot.php' ); + } + + } else if ( 'pause_periodic' == $action ) { + backupbuddy_api::setLiveStatus( $pause_continuous = '', $pause_periodic = true ); + $destination = pb_backupbuddy::$options['remote_destinations'][$destination_id]; // Update local var. + //pb_backupbuddy::disalert( '', __( 'Live File Backup paused. It may take a moment for current processes to finish.', 'it-l10n-backupbuddy' ) ); + $message = __( 'Live File Backup paused. It may take a moment for current processes to finish.', 'it-l10n-backupbuddy' ); + include( pb_backupbuddy::plugin_path() . '/destinations/live/_stats.php' ); // Recalculate stats. + } else if ( 'resume_periodic' == $action ) { + $launchNowText = ' ' . __( 'Unpaused but not running now.', 'it-l10n-backupbuddy' ); + $start_run = false; + if ( '1' != pb_backupbuddy::_GET( 'skip_run_live_now' ) ) { + $launchNowText = ''; + $start_run = true; + } + + backupbuddy_api::setLiveStatus( $pause_continuous = '', $pause_periodic = false, $start_run ); + //pb_backupbuddy::disalert( '', __( 'Live File Backup has resumed.', 'it-l10n-backupbuddy' ) . $launchNowText ); + $message = __( 'Live File Backup has resumed.', 'it-l10n-backupbuddy' ) . $launchNowText; + include( pb_backupbuddy::plugin_path() . '/destinations/live/_stats.php' ); // Recalculate stats. + } else if ( 'pause_continuous' == $action ) { + backupbuddy_api::setLiveStatus( $pause_continuous = true, $pause_periodic = '' ); + $destination = pb_backupbuddy::$options['remote_destinations'][$destination_id]; // Update local var. + include( pb_backupbuddy::plugin_path() . '/destinations/live/_stats.php' ); // Recalculate stats. + //pb_backupbuddy::disalert( '', __( 'Live Database Backup paused.', 'it-l10n-backupbuddy' ) ); + $message = __( 'Live Database Backup paused.', 'it-l10n-backupbuddy' ); + } else if ( 'resume_continuous' == $action ) { + backupbuddy_api::setLiveStatus( $pause_continuous = false, $pause_periodic = '' ); + $destination = pb_backupbuddy::$options['remote_destinations'][$destination_id]; // Update local var. + include( pb_backupbuddy::plugin_path() . '/destinations/live/_stats.php' ); // Recalculate stats. + //pb_backupbuddy::disalert( '', __( 'Live Database Backup resumed.', 'it-l10n-backupbuddy' ) ); + $message = __( 'Live Database Backup resumed.', 'it-l10n-backupbuddy' ); + } else { + $error = 'Error #1000. Invalid request.'; + } + + return array( 'ok' => 1, '_error' => $error, '_message' => $message ); + } + + + + function download_troubleshooting() { + require( pb_backupbuddy::plugin_path() . '/destinations/live/_troubleshooting.php' ); + backupbuddy_live_troubleshooting::run(); + $output = "**File best viewed with wordwrap OFF**\n\n" . print_r( backupbuddy_live_troubleshooting::get_raw_results(), true ); + $backup_prefix = backupbuddy_core::backup_prefix(); + return array( 'output' => $output, 'backup_prefix' => $backup_prefix ); + } + + function get_live_backups() { + $destination_id = $_POST['destination_id']; + // Load required files. + require_once( pb_backupbuddy::plugin_path() . '/destinations/s32/init.php' ); + + if ( ! isset( pb_backupbuddy::$options['remote_destinations'][ $destination_id ] ) ) { + return array( 'error' => 'Error #9828332: Destination not found with id `' . htmlentities( $destination_id ) . '`.' ); + } + require_once( pb_backupbuddy::plugin_path() . '/destinations/stash2/init.php' ); + $settings = &pb_backupbuddy::$options['remote_destinations'][ $destination_id ]; + $settings = pb_backupbuddy_destination_stash2::_formatSettings( $settings ); + + $destination = pb_backupbuddy::$options['remote_destinations'][ $destination_id ]; + + if ( 'live' == $destination['type'] ) { + $remotePath = 'snapshot-';// . backupbuddy_core::backup_prefix(); + $site_only = true; + } else { + // Get list of files for this site. + $remotePath = 'backup-';// . backupbuddy_core::backup_prefix(); + $site_only = true; + } + + $files = pb_backupbuddy_destination_stash2::listFiles( $settings, '', $site_only ); //2nd param was $remotePath. + if ( ! is_array( $files ) ) { + return array( 'error' => 'Error #892329c: ' . $files ); + } + + $backup_list_temp = array(); + foreach( (array)$files as $file ) { + + if ( ( '' != $remotePath ) && ( ! backupbuddy_core::startsWith( basename( $file['filename'] ), $remotePath ) ) ) { // Only show backups for this site unless set to show all. + continue; + } + + $last_modified = $file['uploaded_timestamp']; + $size = (double) $file['size']; + $backup_type = backupbuddy_core::getBackupTypeFromFile( $file['filename'], $quiet = false, $skip_fileoptions = true ); + + // Generate array of table rows. + while( isset( $backup_list_temp[$last_modified] ) ) { // Avoid collisions. + $last_modified += 0.1; + } + + if ( 'live' == $destination['type'] ) { + $backup_list_temp[$last_modified] = array( + array( base64_encode( $file['url'] ), '' . pb_backupbuddy::$format->date( pb_backupbuddy::$format->localize_time( $last_modified ) ) . ' (' . pb_backupbuddy::$format->time_ago( $last_modified ) . ' ago)
' . basename( $file['filename'] ) . '' ), + pb_backupbuddy::$format->date( pb_backupbuddy::$format->localize_time( $last_modified ) ) . '
(' . pb_backupbuddy::$format->time_ago( $last_modified ) . ' ago)', + pb_backupbuddy::$format->file_size( $size ), + backupbuddy_core::pretty_backup_type( $backup_type ), + ); + } else { + $backup_list_temp[$last_modified] = array( + array( base64_encode( $file['url'] ), '' . basename( $file['filename'] ) . '' ), + pb_backupbuddy::$format->date( pb_backupbuddy::$format->localize_time( $last_modified ) ) . '
(' . pb_backupbuddy::$format->time_ago( $last_modified ) . ' ago)', + pb_backupbuddy::$format->file_size( $size ), + backupbuddy_core::pretty_backup_type( $backup_type ), + ); + } + + } + + krsort( $backup_list_temp ); + $backup_list = array(); + foreach( $backup_list_temp as $backup_item ) { + $backup_list[ $backup_item[0][0] ] = $backup_item; + } + unset( $backup_list_temp ); + + return array( 'backup_list' => $backup_list ); + } + + function copy_file_to_local() { + + $file = base64_decode( $_POST['cpy_file'] ); + $destination_id = $_POST['destination_id']; + + // Load required files. + require_once( pb_backupbuddy::plugin_path() . '/destinations/s32/init.php' ); + if ( ! isset( pb_backupbuddy::$options['remote_destinations'][ $destination_id ] ) ) { + return array( 'error' => 'Error #9828332: Destination not found with id `' . htmlentities( $destination_id ) . '`.' ); + } + + $settings = &pb_backupbuddy::$options['remote_destinations'][ $destination_id ]; + $settings = pb_backupbuddy_destination_stash2::_formatSettings( $settings ); + + pb_backupbuddy::status( 'details', 'Scheduling Cron for creating Stash copy.' ); + backupbuddy_core::schedule_single_event( time(), 'process_remote_copy', array( 'stash2', $file, $settings ) ); + if ( '1' != pb_backupbuddy::$options['skip_spawn_cron_call'] ) { + update_option( '_transient_doing_cron', 0 ); // Prevent cron-blocking for next item. + spawn_cron( time() + 150 ); // Adds > 60 seconds to get around once per minute cron running limit. + } + return array( 'ok' => 1 ); + + } + + function delete_file_backup() { + // Handle deletion. + $files = $_POST['items']; + $destination_id = $_POST['destination_id']; + + // Load required files. + require_once( pb_backupbuddy::plugin_path() . '/destinations/s32/init.php' ); + if ( ! isset( pb_backupbuddy::$options['remote_destinations'][ $destination_id ] ) ) { + return array( 'error' => 'Error #9828332: Destination not found with id `' . htmlentities( $destination_id ) . '`.' ); + } + + $settings = &pb_backupbuddy::$options['remote_destinations'][ $destination_id ]; + $settings = pb_backupbuddy_destination_stash2::_formatSettings( $settings ); + + $deleteFiles = array(); + foreach( (array)$files as $file ) { + $file = base64_decode( $file ); + + $startPos = pb_backupbuddy_destination_stash2::strrpos_count( $file, '/', 2 ) + 1; // next to last slash. + $file = substr( $file, $startPos ); + if ( FALSE !== strstr( $file, '?' ) ) { + $file = substr( $file, 0, strpos( $file, '?' ) ); + } + $deleteFiles[] = $file; + } + $response = pb_backupbuddy_destination_stash2::deleteFiles( $settings, $deleteFiles ); + + if ( true === $response ) { + $msg = 'Deleted ' . implode( ', ', $deleteFiles ) . '.'; + } else { + $msg = 'Failed to delete one or more files. Details: `' . $response . '`.'; + } + + return array( 'ok' => 1, 'msg' => $msg ); + } + + function get_live_stats() { + + // Check if running PHP 5.3+. + $php_minimum = 5.3; + if ( version_compare( PHP_VERSION, $php_minimum, '<' ) ) { // Server's PHP is insufficient. + return array('error' => '-1'); + } + + if ( false === ( $stats = backupbuddy_api::getLiveStats() ) ) { // Live is disconnected. + return array('error' => '-1'); + } + + // If there is more to do and too long of time has passed since activity then try to jumpstart the process at the beginning. + if ( ( ( 0 == $stats['files_total'] ) || ( $stats['files_sent'] < $stats['files_total'] ) ) && ( 'wait_on_transfers' != $stats['current_function'] ) ) { // ( Files to send not yet calculated OR more remain to send ) AND not on the wait_on_transfers step. + $time_since_last_activity = microtime( true ) - $stats['last_periodic_activity']; + + if ( $time_since_last_activity < 30 ) { // Don't even bother getting max execution time if it's been less than 30 seconds since run. + // do nothing + } else { // More than 30 seconds since last activity. + + // Detect max PHP execution time. If TESTED value is higher than PHP value then go with that since we want to err on not overlapping processes here. + $detected_execution = backupbuddy_core::detectLikelyHighestExecutionTime(); + + if ( $time_since_last_activity > ( $detected_execution + backupbuddy_constants::TIMED_OUT_PROCESS_RESUME_WIGGLE_ROOM ) ) { // Enough time has passed to assume timed out. + + require_once( pb_backupbuddy::plugin_path() . '/destinations/live/live.php' ); + if ( false === ( $liveID = backupbuddy_live::getLiveID() ) ) { + die( '-1' ); + } + if ( '1' != pb_backupbuddy::$options['remote_destinations'][ $liveID ]['pause_periodic'] ) { // Only proceed if NOT paused. + + pb_backupbuddy::status( 'warning', 'BackupBuddy Stash Live process appears timed out while user it viewing Live page. Forcing run now.' ); + + $cronArgs = array(); + $schedule_result = backupbuddy_core::schedule_single_event( time(), 'live_periodic', $cronArgs ); + if ( true === $schedule_result ) { + pb_backupbuddy::status( 'details', 'Next Live Periodic chunk step cron event scheduled.' ); + } else { + pb_backupbuddy::status( 'error', 'Next Live Periodic chunk step cron event FAILED to be scheduled.' ); + } + if ( '1' != pb_backupbuddy::$options['skip_spawn_cron_call'] ) { + pb_backupbuddy::status( 'details', 'Spawning cron now.' ); + update_option( '_transient_doing_cron', 0 ); // Prevent cron-blocking for next item. + spawn_cron( time() + 150 ); // Adds > 60 seconds to get around once per minute cron running limit. + } + } + + } + } + + } + + return array('result' => json_encode( $stats )); + } + + function save_license_settings() { + $settings = $_POST['settings']; + if (is_array($settings) && isset($GLOBALS['ithemes-updater-settings'])) { + $GLOBALS['ithemes-updater-settings']->update_options( $settings ); + return array('ok' => 1); + } + return false; + } + + function load_products_license() { + $packages = array(); + $packages_name = array(); + if (isset($GLOBALS['ithemes_updater_path'])) { + + require_once( $GLOBALS['ithemes_updater_path'] . '/functions.php' ); + require_once( $GLOBALS['ithemes_updater_path'] . '/api.php' ); + require_once( $GLOBALS['ithemes_updater_path'] . '/keys.php' ); + + require_once( $GLOBALS['ithemes_updater_path'] . '/packages.php' ); + + $details = Ithemes_Updater_Packages::get_full_details(); + $packages = isset($details['packages']) ? $details['packages'] : array(); + if (is_array($packages)) { + foreach ( $packages as $path => $data ) { + $packages_name[$path] = Ithemes_Updater_Functions::get_package_name( $data['package'] ); + } + } + + } + return array('ok' => 1, 'packages' => $packages, 'packages_name' => $packages_name); + } + + function activate_package() { + + $username = $_POST['username']; + $password = $_POST['password']; + $packages = $_POST['packages']; + + $return = array( 'ok' => 1 ); + if (isset($GLOBALS['ithemes_updater_path'])) { + + require_once( $GLOBALS['ithemes_updater_path'] . '/functions.php' ); + require_once( $GLOBALS['ithemes_updater_path'] . '/api.php' ); + require_once( $GLOBALS['ithemes_updater_path'] . '/keys.php' ); + + require_once( $GLOBALS['ithemes_updater_path'] . '/packages.php' ); + + + $response = Ithemes_Updater_API::activate_package( $username, $password, $packages ); + + if ( is_wp_error( $response ) ) { + $errors[] = $this->get_error_explanation( $response ); + $return['errors'] = $errors; + return $return; + } + + if ( empty( $response['packages'] ) ) { + $errors[] = __( 'An unknown server error occurred. Please try to license your products again at another time.', 'it-l10n-backupbuddy' ); + $return['errors'] = $errors; + return $return; + } + + uksort( $response['packages'], 'strnatcasecmp' ); + + $success = array(); + $warn = array(); + $fail = array(); + + foreach ( $response['packages'] as $package => $data ) { + if ( preg_match( '/ \|\|\| \d+$/', $package ) ) + continue; + + $name = Ithemes_Updater_Functions::get_package_name( $package ); + + if ( ! empty( $data['key'] ) ) + $success[] = $name; + else if ( ! empty( $data['status'] ) && ( 'expired' == $data['status'] ) ) + $warn[$name] = __( 'Your product subscription has expired', 'it-l10n-backupbuddy' ); + else + $fail[$name] = $data['error']['message']; + } + + + if ( ! empty( $success ) ) { + $messages[] = wp_sprintf( __( 'Successfully licensed %l.', 'it-l10n-backupbuddy' ), $success ); + $return['messages'] = $messages; + } + + if ( ! empty( $fail ) ) { + foreach ( $fail as $name => $reason ) + $errors[] = sprintf( __( 'Unable to license %1$s. Reason: %2$s', 'it-l10n-backupbuddy' ), $name, $reason ); + $return['errors'] = $errors; + } + + if ( ! empty( $warn ) ) { + foreach ( $warn as $name => $reason ) + $soft_errors[] = sprintf( __( 'Unable to license %1$s. Reason: %2$s', 'it-l10n-backupbuddy' ), $name, $reason ); + $return['soft_errors'] = $soft_errors; + } + + } + return $return; + } + + function deactivate_package( $data ) { + + $username = $_POST['username']; + $password = $_POST['password']; + $packages = $_POST['packages']; + + $return = array( 'ok' => 1 ); + + if (isset($GLOBALS['ithemes_updater_path'])) { + + require_once( $GLOBALS['ithemes_updater_path'] . '/functions.php' ); + require_once( $GLOBALS['ithemes_updater_path'] . '/api.php' ); + require_once( $GLOBALS['ithemes_updater_path'] . '/keys.php' ); + + require_once( $GLOBALS['ithemes_updater_path'] . '/packages.php' ); + + $response = Ithemes_Updater_API::deactivate_package($username, $password, $packages ); + + if ( is_wp_error( $response ) ) { + $errors[] = $this->get_error_explanation( $response ); + $return['errors'] = $errors; + return $return; + } + + if ( empty( $response['packages'] ) ) { + $errors[] = __( 'An unknown server error occurred. Please try to remove licenses from your products again at another time.', 'it-l10n-mainwp-backupbuddy' ); + $return['errors'] = $errors; + return $return; + } + + + uksort( $response['packages'], 'strnatcasecmp' ); + + $success = array(); + $fail = array(); + + foreach ( $response['packages'] as $package => $data ) { + if ( preg_match( '/ \|\|\| \d+$/', $package ) ) + continue; + + $name = Ithemes_Updater_Functions::get_package_name( $package ); + + if ( isset( $data['status'] ) && ( 'inactive' == $data['status'] ) ) + $success[] = $name; + else if ( isset( $data['error'] ) && isset( $data['error']['message'] ) ) + $fail[$name] = $data['error']['message']; + else + $fail[$name] = __( 'Unknown server error.', 'it-l10n-mainwp-backupbuddy' ); + } + + + if ( ! empty( $success ) ) { + $messages[] = wp_sprintf( _n( 'Successfully removed license from %l.', 'Successfully removed licenses from %l.', count( $success ), 'it-l10n-mainwp-backupbuddy' ), $success ); + $return['messages'] = $messages; + } + + if ( ! empty( $fail ) ) { + foreach ( $fail as $name => $reason ) + $errors[] = sprintf( __( 'Unable to remove license from %1$s. Reason: %2$s', 'it-l10n-mainwp-backupbuddy' ), $name, $reason ); + $return['errors'] = $errors; + + } + + } + return $return; + } + + private function get_error_explanation( $error, $package = '' ) { $code = $error->get_error_code(); $package_name = Ithemes_Updater_Functions::get_package_name( $package ); $message = ''; - + switch( $code ) { case 'ITXAPI_Updater_Bad_Login': $message = __( 'Incorrect password. Please make sure that you are supplying your iThemes membership username and password details.', 'it-l10n-mainwp-backupbuddy' ); @@ -2754,18 +2766,18 @@ class MainWP_Child_Back_Up_Buddy { $message = sprintf( __( '%s could not be licensed due to an internal error. Please try to license %s again at a later time. If this problem continues, please contact iThemes support.', 'it-l10n-mainwp-backupbuddy' ), $package_name ); break; } - + if ( empty( $message ) ) { if ( ! empty( $package ) ) $message = sprintf( __( 'An unknown error relating to the %1$s product occurred. Please contact iThemes support. Error details: %2$s', 'it-l10n-mainwp-backupbuddy' ), $package_name, $error->get_error_message() . " ($code)" ); else $message = sprintf( __( 'An unknown error occurred. Please contact iThemes support. Error details: %s', 'it-l10n-mainwp-backupbuddy' ), $error->get_error_message() . " ($code)" ); } - + return $message; } - - - + + + } diff --git a/class/class-mainwp-child-back-up-wordpress.php b/class/class-mainwp-child-back-up-wordpress.php index 4462d88..028b231 100644 --- a/class/class-mainwp-child-back-up-wordpress.php +++ b/class/class-mainwp-child-back-up-wordpress.php @@ -53,6 +53,10 @@ class MainWP_Child_Back_Up_Wordpress { $information['error'] = 'NO_BACKUPWORDPRESS'; MainWP_Helper::write( $information ); } + + if (false === get_option('mainwp_backupwordpress_ext_enabled')) + MainWP_Helper::update_option( 'mainwp_backupwordpress_ext_enabled', 'Y' ); + if ( isset( $_POST['mwp_action'] ) ) { switch ( $_POST['mwp_action'] ) { case 'set_showhide': @@ -171,7 +175,6 @@ class MainWP_Child_Back_Up_Wordpress { } function set_showhide() { - MainWP_Helper::update_option( 'mainwp_backupwordpress_ext_enabled', 'Y' ); $hide = isset( $_POST['showhide'] ) && ( 'hide' === $_POST['showhide'] ) ? 'hide' : ''; MainWP_Helper::update_option( 'mainwp_backupwordpress_hide_plugin', $hide ); $information['result'] = 'SUCCESS'; diff --git a/class/class-mainwp-child-branding.php b/class/class-mainwp-child-branding.php index a8d9ea4..e81273b 100644 --- a/class/class-mainwp-child-branding.php +++ b/class/class-mainwp-child-branding.php @@ -38,7 +38,7 @@ class MainWP_Child_Branding { if ( ! self::is_branding() ) { return $plugin_meta; } - + // hide View details links $meta_total = count( $plugin_meta ); for ( $i = 0; $i < $meta_total; $i++ ) { $str_meta = $plugin_meta[ $i ]; diff --git a/class/class-mainwp-child-server-information.php b/class/class-mainwp-child-server-information.php index e56a7a9..22783e1 100644 --- a/class/class-mainwp-child-server-information.php +++ b/class/class-mainwp-child-server-information.php @@ -30,7 +30,7 @@ class MainWP_Child_Server_Information { } public static function showWarnings() { - if ( stristr( $_SERVER['REQUEST_URI'], 'MainWP_Child_Server_Information' ) ) { + if ( stristr( $_SERVER['REQUEST_URI'], 'mainwp_child_tab' ) || stristr( $_SERVER['REQUEST_URI'], 'mainwp-reports-page' ) || stristr( $_SERVER['REQUEST_URI'], 'mainwp-reports-settings' )) { return; } @@ -124,7 +124,7 @@ class MainWP_Child_Server_Information { $warning = ''; if ( $warnings > 0 ) { - $warning .= 'This site may not connect to your dashboard or may have other issues. Check your MainWP server information page to review and check here for more information on possible fixesDismiss'; + $warning .= 'This site may not connect to your dashboard or may have other issues. Check your MainWP server information page to review and check here for more information on possible fixesDismiss'; } echo $warning; ?> @@ -598,7 +598,7 @@ class MainWP_Child_Server_Information { =', '5.3', 'getPHPVersion' ); + self::renderRow( 'PHP Version', '>=', '5.6', 'getPHPVersion' ); ?> @@ -606,7 +606,7 @@ class MainWP_Child_Server_Information { =', '30', 'getMaxExecutionTime', 'seconds', '=', '0' ); + self::renderRowSec( 'PHP Max Execution Time', '>=', '30', 'getMaxExecutionTime', 'seconds', '=', '0' ); self::renderRowSec( 'PHP Max Input Time', '>=', '30', 'getMaxInputTime', 'seconds', '=', '0' ); self::renderRow( 'PHP Memory Limit', '>=', '128M', 'getPHPMemoryLimit', '(256M+ best for big backups)', null, null, true ); self::renderRow( 'PCRE Backtracking Limit', '>=', '10000', 'getOutputBufferSize' ); @@ -1033,7 +1033,7 @@ class MainWP_Child_Server_Information { Pass' : self::getWarningHTML( $errorType ) ); ?> Pass' : self::getWarningHTML( $errorType ) ); ?> - + Pass'; ?> Pass' : self::getWarningHTML( $errorType )); ?> diff --git a/class/class-mainwp-child-updraft-plus-backups.php b/class/class-mainwp-child-updraft-plus-backups.php index 2353ed4..0268f70 100644 --- a/class/class-mainwp-child-updraft-plus-backups.php +++ b/class/class-mainwp-child-updraft-plus-backups.php @@ -372,17 +372,21 @@ class MainWP_Child_Updraft_Plus_Backups { if ( class_exists( 'UpdraftPlus_Options' ) ) { foreach ( $keys as $key ) { if ( isset( $settings[ $key ] ) ) { - if ( 'updraft_dropbox' === $key ) { - $opts = UpdraftPlus_Options::get_updraft_option( 'updraft_dropbox' ); - $opts['appkey'] = $settings[ $key ]['appkey']; - $opts['secret'] = $settings[ $key ]['secret']; - $opts['folder'] = $settings[ $key ]['folder']; + if ( 'updraft_dropbox' === $key && is_array($settings[ $key ])) { + $opts = UpdraftPlus_Options::get_updraft_option( 'updraft_dropbox' ); + if (isset($settings['is_general']) && !empty($settings['is_general'])){ + $opts['folder'] = $this->replace_tokens($settings[ $key ]['folder']); + } else { + $opts['appkey'] = $settings[ $key ]['appkey']; + $opts['secret'] = $settings[ $key ]['secret']; + $opts['folder'] = $this->replace_tokens($settings[ $key ]['folder']); + } UpdraftPlus_Options::update_updraft_option( $key, $opts ); } else if ( 'updraft_googledrive' === $key ) { $opts = UpdraftPlus_Options::get_updraft_option( 'updraft_googledrive' ); $opts['clientid'] = $settings[ $key ]['clientid']; $opts['secret'] = $settings[ $key ]['secret']; - $opts['folder'] = $settings[ $key ]['folder']; + $opts['folder'] = $this->replace_tokens($settings[ $key ]['folder']); UpdraftPlus_Options::update_updraft_option( $key, $opts ); } else if ( 'updraft_googlecloud' === $key ) { $opts = UpdraftPlus_Options::get_updraft_option( $key ); @@ -397,7 +401,7 @@ class MainWP_Child_Updraft_Plus_Backups { $opts = UpdraftPlus_Options::get_updraft_option( 'updraft_onedrive' ); $opts['clientid'] = $settings[ $key ]['clientid']; $opts['secret'] = $settings[ $key ]['secret']; - $opts['folder'] = $settings[ $key ]['folder']; + $opts['folder'] = $this->replace_tokens($settings[ $key ]['folder']); UpdraftPlus_Options::update_updraft_option( $key, $opts ); } else if ( 'updraft_email' === $key ) { $value = $settings[ $key ]; @@ -408,6 +412,21 @@ class MainWP_Child_Updraft_Plus_Backups { } } UpdraftPlus_Options::update_updraft_option( $key, $value ); + } else if ( 'updraft_s3' === $key ) { + $opts = UpdraftPlus_Options::get_updraft_option( 'updraft_s3' ); + $opts['accesskey'] = $settings[ $key ]['accesskey']; + $opts['secretkey'] = $settings[ $key ]['secretkey']; + $opts['path'] = $this->replace_tokens($settings[ $key ]['path']); + $opts['rrs'] = $settings[ $key ]['rrs']; + $opts['server_side_encryption'] = $settings[ $key ]['server_side_encryption']; + UpdraftPlus_Options::update_updraft_option( $key, $opts ); + } else if ( 'updraft_s3generic' === $key ) { + $opts = UpdraftPlus_Options::get_updraft_option( 'updraft_s3generic' ); + $opts['endpoint'] = $settings[ $key ]['endpoint']; + $opts['accesskey'] = $settings[ $key ]['accesskey']; + $opts['secretkey'] = $settings[ $key ]['secretkey']; + $opts['path'] = $this->replace_tokens($settings[ $key ]['path']); + UpdraftPlus_Options::update_updraft_option( $key, $opts ); } else { UpdraftPlus_Options::update_updraft_option( $key, $settings[ $key ] ); } @@ -452,7 +471,24 @@ class MainWP_Child_Updraft_Plus_Backups { return $out; } - function addons_connect() { + function replace_tokens($str = '') { + if (stripos($str, '%sitename%') !== false) { + $replace_token = get_bloginfo( 'name' ); + $replace_token = sanitize_file_name($replace_token); + $replace_token = strtolower($replace_token); + $str = str_ireplace("%sitename%", $replace_token, $str); + } + + if (stripos($str, '%siteurl%') !== false) { + $replace_token = get_bloginfo( 'url' ); + $replace_token = preg_replace('/^https?:\/\//i', '', $replace_token); + $replace_token = sanitize_file_name($replace_token); + $str = str_ireplace("%siteurl%", $replace_token, $str); + } + return $str; + } + + function addons_connect() { if ( ! defined( 'UDADDONS2_SLUG' ) ) { return array( 'error' => 'NO_PREMIUM' ); } @@ -1326,12 +1362,7 @@ class MainWP_Child_Updraft_Plus_Backups { $mess = array(); parse_str( $_POST['restoreopts'], $res ); - - // error_log(print_r($_POST, true)); - // error_log(print_r($res, true)); - - if ( isset( $res['updraft_restore'] ) ) { - + if ( isset( $res['updraft_restore'] ) ) { set_error_handler( array( $this, 'get_php_errors' ), E_ALL & ~E_STRICT ); $elements = array_flip( $res['updraft_restore'] ); diff --git a/class/class-mainwp-child-wordfence.php b/class/class-mainwp-child-wordfence.php index 63e19c9..afc7897 100644 --- a/class/class-mainwp-child-wordfence.php +++ b/class/class-mainwp-child-wordfence.php @@ -8,11 +8,13 @@ class MainWP_Child_Wordfence { public static $options_filter = array( 'alertEmails', 'alertOn_adminLogin', + 'alertOn_firstAdminLoginOnly', 'alertOn_block', 'alertOn_critical', 'alertOn_loginLockout', 'alertOn_lostPasswdForm', 'alertOn_nonAdminLogin', + 'alertOn_firstNonAdminLoginOnly', 'alertOn_update', 'alertOn_warnings', 'alert_maxHourly', @@ -101,6 +103,7 @@ class MainWP_Child_Wordfence { 'email_summary_interval', 'email_summary_excluded_directories', 'allowed404s', + 'wafAlertOnAttacks' //'ajaxWatcherDisabled_front', // do not update those values when save settings //'ajaxWatcherDisabled_admin' ); diff --git a/class/class-mainwp-child.php b/class/class-mainwp-child.php index 982ee2a..c6da634 100644 --- a/class/class-mainwp-child.php +++ b/class/class-mainwp-child.php @@ -417,7 +417,7 @@ class MainWP_Child { $fix_update_plugins = array(); if ( is_array( $plugin_updates ) ) { foreach ( $plugin_updates as $slug => $plugin_update ) { - if ( in_array( $slug, array( 'ithemes-security-pro/ithemes-security-pro.php', 'monarch/monarch.php', 'cornerstone/cornerstone.php') ) ) { + if ( in_array( $slug, array( 'ithemes-security-pro/ithemes-security-pro.php', 'monarch/monarch.php', 'cornerstone/cornerstone.php', 'updraftplus/updraftplus.php') ) ) { $fix_update_plugins[ $slug ] = $plugin_update; } } @@ -1515,7 +1515,7 @@ class MainWP_Child { if ( ! empty( $fileName ) ) { do_action( 'mainwp_child_installPluginTheme', $args ); if ( isset( $_POST['activatePlugin'] ) && 'yes' === $_POST['activatePlugin'] ) { - activate_plugin( $path . $fileName, '', false, true ); + activate_plugin( $path . $fileName, '' /* false, true */ ); do_action( 'activate_plugin', $args['slug'], null ); } } @@ -2128,6 +2128,14 @@ class MainWP_Child { update_post_meta( $postId, $key, $meta_value[ $i ] ); } } + } else if ( 'get_edit' === $action ) { + $postId = $_POST['id']; + $post_type = $_POST['post_type']; + if ( $post_type == 'post' ) { + $my_post = $this->get_post_edit( $postId ); + } else { + $my_post = $this->get_page_edit( $postId ); + } } else { $information['status'] = 'FAIL'; } @@ -2139,6 +2147,152 @@ class MainWP_Child { MainWP_Helper::write( $information ); } + function get_post_edit($id) { + $post = get_post( $id ); + if ( $post ) { + $categoryObjects = get_the_category( $post->ID ); + $categories = ''; + foreach ( $categoryObjects as $cat ) { + if ( '' !== $categories ) { + $categories .= ', '; + } + $categories .= $cat->name; + } + $post_category = $categories; + + $tagObjects = get_the_tags( $post->ID ); + $tags = ''; + if ( is_array( $tagObjects ) ) { + foreach ( $tagObjects as $tag ) { + if ( '' !== $tags ) { + $tags .= ', '; + } + $tags .= $tag->name; + } + } + $post_tags = $tags; + + $post_custom = get_post_custom( $id ); + + $galleries = get_post_gallery( $id, false ); + $post_gallery_images = array(); + + if ( is_array($galleries) && isset($galleries['ids']) ) { + $attached_images = explode( ',', $galleries['ids'] ); + foreach( $attached_images as $attachment_id ) { + $attachment = get_post( $attachment_id ); + if ( $attachment ) { + $post_gallery_images[] = array( + 'id' => $attachment_id, + 'alt' => get_post_meta( $attachment->ID, '_wp_attachment_image_alt', true ), + 'caption' => $attachment->post_excerpt, + 'description' => $attachment->post_content, + 'src' => $attachment->guid, + 'title' => $attachment->post_title + ); + } + } + } + + include_once( ABSPATH . 'wp-includes' . DIRECTORY_SEPARATOR . 'post-thumbnail-template.php' ); + $post_featured_image = get_post_thumbnail_id( $id ); + $child_upload_dir = wp_upload_dir(); + $new_post = array( + 'edit_id' => $id, + 'is_sticky' => is_sticky( $id ) ? 1 : 0, + 'post_title' => $post->post_title, + 'post_content' => $post->post_content, + 'post_status' => $post->post_status, //was 'publish' + 'post_date' => $post->post_date, + 'post_date_gmt' => $post->post_date_gmt, + 'post_tags' => $post_tags, + 'post_name' => $post->post_name, + 'post_excerpt' => $post->post_excerpt, + 'comment_status' => $post->comment_status, + 'ping_status' => $post->ping_status + ); + + if ( $post_featured_image != null ) { //Featured image is set, retrieve URL + $img = wp_get_attachment_image_src( $post_featured_image, 'full' ); + $post_featured_image = $img[0]; + } + + $post_data = array( + 'new_post' => base64_encode( serialize( $new_post ) ), + 'post_custom' => base64_encode( serialize( $post_custom ) ), + 'post_category' => base64_encode( $post_category ), + 'post_featured_image' => base64_encode( $post_featured_image ), + 'post_gallery_images' => base64_encode( serialize( $post_gallery_images ) ), + 'child_upload_dir' => base64_encode( serialize( $child_upload_dir ) ), + ); + return $post_data; + + } + return false; + } + + function get_page_edit($id) { + $post = get_post( $id ); + if ( $post ) { + $post_custom = get_post_custom( $id ); + //post_slug = base64_decode( get_post_meta( $id, '_slug', true ) ); + include_once( ABSPATH . 'wp-includes' . DIRECTORY_SEPARATOR . 'post-thumbnail-template.php' ); + $post_featured_image = get_post_thumbnail_id( $id ); + $child_upload_dir = wp_upload_dir(); + + $new_post = array( + 'edit_id' => $id, + 'post_title' => $post->post_title, + 'post_content' => $post->post_content, + 'post_status' => $post->post_status, + 'post_date' => $post->post_date, + 'post_date_gmt' => $post->post_date_gmt, + 'post_type' => 'page', + 'post_name' => $post->post_name, + 'post_excerpt' => $post->post_excerpt, + 'comment_status' => $post->comment_status, + 'ping_status' => $post->ping_status + ); + + + if ( $post_featured_image != null ) { //Featured image is set, retrieve URL + $img = wp_get_attachment_image_src( $post_featured_image, 'full' ); + $post_featured_image = $img[0]; + } + + $galleries = get_post_gallery( $id, false ); + $post_gallery_images = array(); + + if ( is_array($galleries) && isset($galleries['ids']) ) { + $attached_images = explode( ',', $galleries['ids'] ); + foreach( $attached_images as $attachment_id ) { + $attachment = get_post( $attachment_id ); + if ( $attachment ) { + $post_gallery_images[] = array( + 'id' => $attachment_id, + 'alt' => get_post_meta( $attachment->ID, '_wp_attachment_image_alt', true ), + 'caption' => $attachment->post_excerpt, + 'description' => $attachment->post_content, + 'src' => $attachment->guid, + 'title' => $attachment->post_title + ); + } + } + } + + $post_data = array( + 'new_post' => base64_encode( serialize( $new_post ) ), + 'post_custom' => base64_encode( serialize( $post_custom ) ), + 'post_featured_image' => base64_encode( $post_featured_image ), + 'post_gallery_images' => base64_encode( serialize( $post_gallery_images ) ), + 'child_upload_dir' => base64_encode( serialize( $child_upload_dir ) ), + ); + return $post_data; + } + return false; + } + + function user_action() { //Read form data $action = $_POST['action']; @@ -2149,9 +2303,9 @@ class MainWP_Child { global $current_user; $reassign = ( isset( $current_user ) && isset( $current_user->ID ) ) ? $current_user->ID : 0; - + include_once( ABSPATH . '/wp-admin/includes/user.php' ); + if ( 'delete' === $action ) { - include_once( ABSPATH . '/wp-admin/includes/user.php' ); wp_delete_user( $userId, $reassign ); } else if ( 'changeRole' === $action ) { $my_user = array(); @@ -3234,12 +3388,13 @@ class MainWP_Child { } $information['recent_comments'] = $this->get_recent_comments( array( 'approve', 'hold' ), 5 ); - $information['recent_posts'] = $this->get_recent_posts( array( 'publish', 'draft', 'pending', 'trash' ), 5 ); + $information['recent_posts'] = $this->get_recent_posts( array( 'publish', 'draft', 'pending', 'trash', 'future' ), 5 ); $information['recent_pages'] = $this->get_recent_posts( array( 'publish', 'draft', 'pending', 'trash', + 'future' ), 5, 'page' ); $securityIssuess = 0; diff --git a/class/class-mainwp-client-report.php b/class/class-mainwp-client-report.php index 37a9090..61265b6 100644 --- a/class/class-mainwp-client-report.php +++ b/class/class-mainwp-client-report.php @@ -241,8 +241,12 @@ class MainWP_Client_Report { } } + if ( MainWP_Child_Branding::is_branding() ) { + $args['hide_child_reports'] = 1; + } + $args['records_per_page'] = 9999; - // error_log(print_r($args, true)); + if ( self::$mainwpChildReports ) { $records = mainwp_wp_stream_query( $args ); diff --git a/class/class-mainwp-helper.php b/class/class-mainwp-helper.php index 4b5df6a..a83fd01 100644 --- a/class/class-mainwp-helper.php +++ b/class/class-mainwp-helper.php @@ -121,17 +121,26 @@ class MainWP_Helper { } - static function uploadImage( $img_url, $img_data = array() ) { + static function uploadImage( $img_url, $img_data = array() , $check_file_existed = false ) { if (!is_array($img_data)) $img_data = array(); include_once( ABSPATH . 'wp-admin/includes/file.php' ); //Contains download_url + $upload_dir = wp_upload_dir(); + + if ($check_file_existed) { + $local_img_url = $upload_dir['url'] . '/' . basename( $img_url ); + $attach_id = MainWP_Helper::get_image_id($local_img_url); + if ($attach_id) { + return array( 'id' => $attach_id, 'url' => $local_img_url ); + } + } + //Download $img_url $temporary_file = download_url( $img_url ); if ( is_wp_error( $temporary_file ) ) { throw new Exception( 'Error: ' . $temporary_file->get_error_message() ); } else { - $upload_dir = wp_upload_dir(); $local_img_path = $upload_dir['path'] . DIRECTORY_SEPARATOR . basename( $img_url ); //Local name $local_img_url = $upload_dir['url'] . '/' . basename( $img_url ); $moved = @rename( $temporary_file, $local_img_path ); @@ -160,6 +169,12 @@ class MainWP_Helper { return null; } + static function get_image_id($image_url) { + global $wpdb; + $attachment = $wpdb->get_col($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE guid='%s';", $image_url )); + return $attachment[0]; + } + static function uploadFile( $file_url, $path, $file_name ) { $file_name = sanitize_file_name( $file_name ); $full_file_name = $path . DIRECTORY_SEPARATOR . $file_name; //Local name @@ -272,6 +287,11 @@ class MainWP_Helper { $wpr_options = isset( $_POST['wpr_options'] ) ? $_POST['wpr_options'] : array(); + $edit_post_id = 0; + if ( isset( $post_custom['_mainwp_edit_post_id'] ) && $post_custom['_mainwp_edit_post_id'] ) { + $edit_post_id = current($post_custom['_mainwp_edit_post_id']); + } + //Search for all the images added to the new post //some images have a href tag to click to navigate to the image.. we need to replace this too $foundMatches = preg_match_all( '/(]+href=\"(.*?)\"[^>]*>)?(\/]*src=\"((.*?)(png|gif|jpg|jpeg))\")/ix', $new_post['post_content'], $matches, PREG_SET_ORDER ); @@ -294,7 +314,13 @@ class MainWP_Helper { } try { - $downloadfile = MainWP_Helper::uploadImage( $originalImgUrl ); + // in the case edit post will check if file existed + if ( $edit_post_id ) { + $downloadfile = MainWP_Helper::uploadImage( $originalImgUrl , array(), true ); + } else { + $downloadfile = MainWP_Helper::uploadImage( $originalImgUrl ); + } + $localUrl = $downloadfile['url']; $linkToReplaceWith = dirname( $localUrl ); if ( '' !== $hrefLink ) { @@ -407,6 +433,16 @@ class MainWP_Helper { remove_filter( 'content_save_pre', 'wp_filter_post_kses' ); // to fix brake scripts or html $post_status = $new_post['post_status']; $new_post['post_status'] = 'auto-draft'; + + // update post + if ( $edit_post_id ) { + // check if post existed + $current_post = get_post($edit_post_id); + if ( $current_post && ( ( !isset( $new_post['post_type'] ) && $current_post->post_type == 'post' ) || ( isset( $new_post['post_type'] ) && $new_post['post_type'] == $current_post->post_type ) ) ) { + $new_post['ID'] = $edit_post_id; + } + } + $new_post_id = wp_insert_post( $new_post, $wp_error ); //Show errors if something went wrong @@ -461,6 +497,9 @@ class MainWP_Helper { $not_allowed[] = '_saved_draft_publish_date_to'; $not_allowed[] = '_post_to_only_existing_categories'; $not_allowed[] = '_mainwp_robot_post_comments'; + $not_allowed[] = '_mainwp_edit_post_site_id'; + $not_allowed[] = '_mainwp_edit_post_id'; + $not_allowed[] = '_edit_post_status'; $post_to_only_existing_categories = false; foreach ( $post_custom as $meta_key => $meta_values ) { @@ -472,10 +511,10 @@ class MainWP_Helper { if ( ! $seo_ext_activated ) { // if Wordpress SEO plugin is not activated do not save yoast post meta if ( strpos( $meta_key, '_yoast_wpseo_' ) === false ) { - add_post_meta( $new_post_id, $meta_key, $meta_value ); + update_post_meta( $new_post_id, $meta_key, $meta_value ); } } else { - add_post_meta( $new_post_id, $meta_key, $meta_value ); + update_post_meta( $new_post_id, $meta_key, $meta_value ); } } } else if ( '_sticky' === $meta_key ) { @@ -536,6 +575,7 @@ class MainWP_Helper { } } + $featured_image_exist = false; //If featured image exists - set it if ( null !== $post_featured_image ) { try { @@ -543,12 +583,17 @@ class MainWP_Helper { if ( null !== $upload ) { update_post_meta( $new_post_id, '_thumbnail_id', $upload['id'] ); //Add the thumbnail to the post! + $featured_image_exist = true; } } catch ( Exception $e ) { } } + if ( !$featured_image_exist ) { + delete_post_meta( $new_post_id, '_thumbnail_id' ); + } + // post plus extension process if ( $is_post_plus ) { $random_privelege = isset( $post_custom['_saved_draft_random_privelege'] ) ? $post_custom['_saved_draft_random_privelege'] : null; @@ -590,6 +635,12 @@ class MainWP_Helper { } // end of post plus + // to support custom post author + $custom_post_author = apply_filters('mainwp_create_post_custom_author', false, $new_post_id); + if ( !empty( $custom_post_author ) ) { + wp_update_post( array( 'ID' => $new_post_id, 'post_author' => $custom_post_author ) ); + } + // MainWP Robot if ( $is_robot_post ) { $all_comments = $post_custom['_mainwp_robot_post_comments']; diff --git a/class/class-mainwp-keyword-links.php b/class/class-mainwp-keyword-links.php index 41af040..9a80c93 100644 --- a/class/class-mainwp-keyword-links.php +++ b/class/class-mainwp-keyword-links.php @@ -131,7 +131,6 @@ class MainWP_Keyword_Links { if ( empty( $redirection_folder ) ) { $rules = $this->get_cloak_rules(); $rules = $this->mod_rewrite_rules( $rules ); - //error_log(print_r($rules, true)); //self::clear_htaccess(); } else { //Create rewrite ruler