Пример #1
0
    public static function backups_list($type = 'default', $subsite_mode = false)
    {
        if (pb_backupbuddy::_POST('bulk_action') == 'delete_backup' && is_array(pb_backupbuddy::_POST('items'))) {
            $needs_save = false;
            pb_backupbuddy::verify_nonce(pb_backupbuddy::_POST('_wpnonce'));
            // Security check to prevent unauthorized deletions by posting from a remote place.
            $deleted_files = array();
            foreach (pb_backupbuddy::_POST('items') 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);
                        $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 = self::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;
                        }
                    } else {
                        pb_backupbuddy::alert('Error: Unable to delete backup file `' . $item . '`. Please verify permissions.', true);
                    }
                }
                // End if file exists.
            }
            // End foreach.
            if ($needs_save === true) {
                pb_backupbuddy::save();
            }
            pb_backupbuddy::alert(__('Deleted:', 'it-l10n-backupbuddy') . ' ' . implode(', ', $deleted_files));
        }
        // End if deleting backup(s).
        $backups = array();
        $backup_sort_dates = array();
        $files = glob(backupbuddy_core::getBackupDirectory() . 'backup*.zip');
        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 = self::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';
                    pb_backupbuddy::status('details', 'Fileoptions instance #33.');
                    $backup_options = new pb_backupbuddy_fileoptions(backupbuddy_core::getLogDirectory() . 'fileoptions/' . $serial . '.txt', $read_only = false, $ignore_lock = false, $create_file = true);
                    // Will create file to hold integrity data if nothing exists.
                } else {
                    $backup_options = '';
                }
                $backup_integrity = backupbuddy_core::backup_integrity_check($file, $backup_options, $options);
                // Backup status.
                $pretty_status = array(true => '<span class="pb_label pb_label-success">Good</span>', 'pass' => '<span class="pb_label pb_label-success">Good</span>', false => '<span class="pb_label pb_label-important">Bad</span>', 'fail' => '<span class="pb_label pb_label-important">Bad</span>');
                // Backup type.
                $pretty_type = array('full' => 'Full', 'db' => 'Database', 'files' => 'Files');
                // 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.
                    $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 = 'Unknown';
                    } else {
                        if (isset($backup_options->options['profile'])) {
                            $detected_type = '
							<div>
								<span style="color: #AAA; float: left;">' . $detected_type . '</span>
								<span style="display: inline-block; float: left; height: 15px; border-right: 1px solid #EBEBEB; margin-left: 6px; margin-right: 6px;"></span>
								' . htmlentities($backup_options->options['profile']['title']) . '
							</div>
							';
                        }
                    }
                    $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'];
                    if (isset($backup_integrity['status'])) {
                        // Pre-v4.0.
                        $status = $backup_integrity['status'];
                    } else {
                        // v4.0+
                        $status = $backup_integrity['is_ok'];
                    }
                    // Calculate main row string.
                    if ($type == 'default') {
                        // Default backup listing.
                        $main_string = '<a href="' . pb_backupbuddy::ajax_url('download_archive') . '&backupbuddy_backup=' . basename($file) . '" class="backupbuddyFileTitle" title="' . basename($file) . '">' . $modified . ' (' . $time_ago . ')</a>';
                    } elseif ($type == 'migrate') {
                        // Migration backup listing.
                        $main_string = '<a class="pb_backupbuddy_hoveraction_migrate backupbuddyFileTitle" rel="' . basename($file) . '" href="' . pb_backupbuddy::page_url() . '&migrate=' . basename($file) . '&value=' . basename($file) . '" title="' . basename($file) . '">' . $modified . ' (' . $time_ago . ')</a>';
                    } else {
                        $main_string = '{Unknown type.}';
                    }
                    // Add comment to main row string if applicable.
                    if (isset($backup_integrity['comment']) && $backup_integrity['comment'] !== false && $backup_integrity['comment'] !== '') {
                        $main_string .= '<br><span class="description">Note: <span class="pb_backupbuddy_notetext">' . htmlentities($backup_integrity['comment']) . '</span></span>';
                    }
                    $integrity = pb_backupbuddy::$format->prettify($status, $pretty_status) . ' ';
                    if (isset($backup_integrity['scan_notes']) && count((array) $backup_integrity['scan_notes']) > 0) {
                        foreach ((array) $backup_integrity['scan_notes'] as $scan_note) {
                            $integrity .= $scan_note . ' ';
                        }
                    }
                    $integrity .= '<a href="' . pb_backupbuddy::page_url() . '&reset_integrity=' . $serial . '" title="Rescan integrity. Last checked ' . pb_backupbuddy::$format->date($backup_integrity['scan_time']) . '."><img src="' . pb_backupbuddy::plugin_url() . '/images/refresh_gray.gif" style="vertical-align: -1px;"></a>';
                    $integrity .= '<div class="row-actions"><a title="' . __('Backup Status', 'it-l10n-backupbuddy') . '" href="' . pb_backupbuddy::ajax_url('integrity_status') . '&serial=' . $serial . '&#038;TB_iframe=1&#038;width=640&#038;height=600" class="thickbox">' . __('View Details', 'it-l10n-backupbuddy') . '</a></div>';
                    $sumLogFile = backupbuddy_core::getLogDirectory() . 'status-' . $serial . '_sum_' . pb_backupbuddy::$options['log_serial'] . '.txt';
                    if (file_exists($sumLogFile)) {
                        $integrity .= '<div class="row-actions"><a title="' . __('View Backup Log', 'it-l10n-backupbuddy') . '" href="' . pb_backupbuddy::ajax_url('view_log') . '&serial=' . $serial . '&#038;TB_iframe=1&#038;width=640&#038;height=600" class="thickbox">' . __('View Log', 'it-l10n-backupbuddy') . '</a></div>';
                    }
                }
                // end if is_array( $backup_options ).
                $backups[basename($file)] = array(array(basename($file), $main_string . '<br><span class="description" style="color: #AAA; display: inline-block; margin-top: 5px;">' . basename($file) . '</span>'), $detected_type, $file_size, $integrity);
                $backup_sort_dates[basename($file)] = $modified_time;
            }
            // End foreach().
        }
        // End if.
        // Sort backup by date.
        arsort($backup_sort_dates);
        // Re-arrange backups based on sort dates.
        $sorted_backups = array();
        foreach ($backup_sort_dates as $backup_file => $backup_sort_date) {
            $sorted_backups[$backup_file] = $backups[$backup_file];
            unset($backups[$backup_file]);
        }
        unset($backups);
        return $sorted_backups;
    }
Пример #2
0
 function integrity_check()
 {
     pb_backupbuddy::status('milestone', 'start_integrity');
     pb_backupbuddy::status('message', __('Scanning and verifying backup file integrity.', 'it-l10n-backupbuddy'));
     if ($this->_backup['profile']['type'] != 'files' && $this->_backup['profile']['skip_database_dump'] == '1') {
         pb_backupbuddy::status('warning', 'WARNING: Database .SQL file does NOT exist because the database dump has been set to be SKIPPED based on settings. Use with caution!');
     }
     $options = array('skip_database_dump' => $this->_backup['profile']['skip_database_dump']);
     pb_backupbuddy::status('details', 'Starting integrity check on `' . $this->_backup['archive_file'] . '`.');
     $result = backupbuddy_core::backup_integrity_check($this->_backup['archive_file'], $this->_backup_options, $options, $skipLogRedirect = true);
     if (false === $result['is_ok']) {
         $message = __('Backup failed to pass integrity check. The backup may have failed OR the backup may be valid but the integrity check could not verify it. This could be due to permissions, large file size, running out of memory, or other error. Verify you have not excluded one or more required files, paths, or database tables; check for warnings above in the status log.  You may wish to manually verify the backup file is functional or re-scan.', 'it-l10n-backupbuddy');
         pb_backupbuddy::status('error', $message);
         pb_backupbuddy::status('details', 'Running cleanup procedure now in current step as backup procedure is halting.');
         $this->post_backup(true);
         // Post backup cleanup in fail mode.
         //pb_backupbuddy::status( 'haltScript', '' ); // Halt JS on page.
         pb_backupbuddy::status('details', __('Sending integrity check failure email.', 'it-l10n-backupbuddy'));
         backupbuddy_core::mail_error($message);
         return false;
     }
     pb_backupbuddy::status('milestone', 'finish_integrity');
     return true;
 }