public function testBackUpDirIsExcludedWhenBackUpDirIsInRoot()
 {
     HM\BackUpWordPress\Path::get_instance()->set_path(dirname(__FILE__) . '/test-data/tmp');
     $this->assertContains($this->backup->get_root(), hmbkp_path());
     $this->assertNotEmpty($this->backup->get_excludes());
     $this->assertContains(trailingslashit(hmbkp_path()), $this->backup->get_excludes());
 }
Exemple #2
0
function hmbkp_backup_complete($backup)
{
    if ($backup->errors()) {
        hmbkp_cleanup();
        $file = hmbkp_path() . '/.backup_errors';
        if (file_exists($file)) {
            unlink($file);
        }
        if (!($handle = @fopen($file, 'w'))) {
            return;
        }
        fwrite($handle, json_encode($backup->errors()));
        fclose($handle);
    } elseif ($backup->warnings()) {
        $file = hmbkp_path() . '/.backup_warnings';
        if (file_exists($file)) {
            unlink($file);
        }
        if (!($handle = @fopen($file, 'w'))) {
            return;
        }
        fwrite($handle, json_encode($backup->warnings()));
        fclose($handle);
    }
}
 /**
  * Cleanup the backup file and tmp directory
  * after every test
  *
  * @access public
  */
 public function tearDown()
 {
     hmbkp_rmdirtree(hmbkp_path());
     delete_option('hmbkp_path');
     delete_option('hmbkp_default_path');
     unset($this->backup);
 }
 /**
  * Cleanup the backup file and tmp directory
  * after every test
  *
  */
 public function tearDown()
 {
     hmbkp_rmdirtree(hmbkp_path());
     chmod($this->backup->get_root() . '/test-data.txt', 0664);
     unset($this->backup);
     HM\BackUpWordPress\Path::get_instance()->reset_path();
 }
 public function testDeltaBackupWithCommands()
 {
     if (!$this->backup->get_zip_command_path()) {
         $this->markTestSkipped('Empty zip command path');
     }
     if (!$this->backup->get_mysqldump_command_path()) {
         $this->markTestSkipped('Empty mysqldump command path');
     }
     $this->backup->backup();
     $this->assertEquals('zip', $this->backup->get_archive_method());
     $this->assertEquals('mysqldump', $this->backup->get_mysqldump_method());
     $this->assertFileExists($this->backup->get_archive_filepath());
     $this->assertArchiveContains($this->backup->get_archive_filepath(), array('test-data.txt', $this->backup->get_database_dump_filename()));
     $this->assertArchiveFileCount($this->backup->get_archive_filepath(), 4);
     if (!copy($this->backup->get_archive_filepath(), hmbkp_path() . '/delta.zip')) {
         $this->markTestSkipped('Unable to copy backup');
     }
     // create a new file
     file_put_contents($this->backup->get_root() . '/new.file', 'test');
     if (!file_exists($this->backup->get_root() . '/new.file')) {
         $this->markTestSkipped('new.file couldn\'t be created');
     }
     $this->backup->set_archive_filename('delta.zip');
     $this->backup->backup();
     $this->assertFileExists($this->backup->get_archive_filepath());
     $this->assertArchiveContains($this->backup->get_archive_filepath(), array('new.file', 'test-data.txt', $this->backup->get_database_dump_filename()));
     $this->assertArchiveFileCount($this->backup->get_archive_filepath(), 5);
 }
 /**
  * Cleanup the backup file and tmp directory
  * after every test
  *
  */
 public function tearDown()
 {
     hmbkp_rmdirtree(hmbkp_path());
     unset($this->backup);
     if (file_exists($this->symlink)) {
         unlink($this->symlink);
     }
     HM\BackUpWordPress\Path::get_instance()->reset_path();
 }
 /**
  * Cleanup the backup file and tmp directory
  * after every test
  *
  * @access public
  */
 public function tearDown()
 {
     hmbkp_rmdirtree($this->backup->get_path());
     hmbkp_rmdirtree(hmbkp_path());
     delete_option('hmbkp_path');
     delete_option('hmbkp_default_path');
     chmod($this->backup->get_root() . '/test-data.txt', 0664);
     unset($this->backup);
 }
 /**
  * Cleanup the backup file and tmp directory
  * after every test
  *
  */
 public function tearDown()
 {
     if (!function_exists('symlink')) {
         return;
     }
     hmbkp_rmdirtree(hmbkp_path());
     unset($this->backup);
     @unlink($this->symlink);
     HM\BackUpWordPress\Path::get_instance()->reset_path();
 }
 /**
  * Cleanup the backup file and tmp directory
  * after every test
  *
  * @access public
  */
 public function tearDown()
 {
     hmbkp_rmdirtree($this->backup->get_path());
     hmbkp_rmdirtree(hmbkp_path());
     delete_option('hmbkp_path');
     delete_option('hmbkp_default_path');
     unset($this->backup);
     if (file_exists($this->hidden)) {
         unlink($this->hidden);
     }
 }
 /**
  * What if the backup path is in root
  *
  */
 public function testRootBackupPath()
 {
     HM\BackUpWordPress\Path::get_instance()->set_path('/');
     $this->backup->set_archive_filename('backup.zip');
     $this->assertEquals('/', hmbkp_path());
     $this->assertEquals('/backup.zip', $this->backup->get_archive_filepath());
     if (!is_writable(hmbkp_path())) {
         $this->markTestSkipped('Root not writable');
     }
     $this->backup->backup();
     $this->assertFileExists($this->backup->get_archive_filepath());
 }
 /**
  * Cleanup the backup file and tmp directory
  * after every test
  *
  * @access public
  */
 public function tearDown()
 {
     if (!function_exists('symlink')) {
         return;
     }
     hmbkp_rmdirtree($this->backup->get_path());
     hmbkp_rmdirtree(hmbkp_path());
     delete_option('hmbkp_path');
     delete_option('hmbkp_default_path');
     unset($this->backup);
     @unlink($this->symlink);
 }
Exemple #12
0
/**
 * Setup the HM_Backup class
 *
 * @return null
 */
function hmbkp_setup_hm_backup()
{
    $hm_backup = HM_Backup::get_instance();
    $hm_backup->path = hmbkp_path();
    $hm_backup->files_only = hmbkp_get_files_only();
    $hm_backup->database_only = hmbkp_get_database_only();
    if (defined('HMBKP_MYSQLDUMP_PATH')) {
        $hm_backup->mysql_command_path = HMBKP_MYSQLDUMP_PATH;
    }
    if (defined('HMBKP_ZIP_PATH')) {
        $hm_backup->zip_command_path = HMBKP_ZIP_PATH;
    }
    $hm_backup->excludes = hmbkp_valid_custom_excludes();
}
 /**
  * Perform a Backup.
  *
  * ## OPTIONS
  *
  * [--files_only]
  * : Backup files only, default to off
  *
  * [--database_only]
  * : Backup database only, defaults to off
  *
  * [--destination]
  * : dir that the backup should be save in, defaults to your existing backups directory
  *
  * [--root]
  * : dir that should be backed up, defaults to site root.
  *
  * [--zip_command_path]
  * : path to your zip binary, standard locations are automatically used
  *
  * [--mysqldump_command_path]
  * : path to your mysqldump binary, standard locations are automatically used
  *
  * [--archive_filename]
  * : filename for the resulting zip file
  *
  * [--excludes]
  * : list of paths you'd like to exclude
  *
  * ## Usage
  *
  *     wp backupwordpress backup [--files_only] [--database_only] [--path<dir>] [--root<dir>] [--zip_command_path=<path>] [--mysqldump_command_path=<path>]
  *
  * @todo errors should be bubbled from Backup, Scheduled_Backup and the like instead of being repeated.
  */
 public function backup($args, $assoc_args)
 {
     add_action('hmbkp_mysqldump_started', function () {
         WP_CLI::line(__('Backup: Dumping database...', 'backupwordpress'));
     });
     add_action('hmbkp_archive_started', function () {
         WP_CLI::line(__('Backup: Zipping everything up...', 'backupwordpress'));
     });
     $hm_backup = new HM\BackUpWordPress\Backup();
     if (!empty($assoc_args['destination'])) {
         Path::get_instance()->set_path($assoc_args['destination']);
     }
     HM\BackUpWordPress\Path::get_instance()->cleanup();
     if (!empty($assoc_args['root'])) {
         $hm_backup->set_root($assoc_args['root']);
     }
     if (!is_dir(hmbkp_path())) {
         WP_CLI::error(__('Invalid backup path', 'backupwordpress'));
         return false;
     }
     if (!is_dir($hm_backup->get_root()) || !is_readable($hm_backup->get_root())) {
         WP_CLI::error(__('Invalid root path', 'backupwordpress'));
         return false;
     }
     if (isset($assoc_args['archive_filename'])) {
         $hm_backup->set_archive_filename($assoc_args['archive_filename']);
     }
     if (!empty($assoc_args['files_only'])) {
         $hm_backup->set_type('file');
     }
     if (!empty($assoc_args['database_only'])) {
         $hm_backup->set_type('database');
     }
     if (isset($assoc_args['mysqldump_command_path'])) {
         $hm_backup->set_mysqldump_command_path($assoc_args['mysqldump_command_path']);
     }
     if (isset($assoc_args['zip_command_path'])) {
         $hm_backup->set_zip_command_path($assoc_args['zip_command_path']);
     }
     if (!empty($assoc_args['excludes'])) {
         $hm_backup->set_excludes($assoc_args['excludes']);
     }
     $hm_backup->backup();
     if (file_exists($hm_backup->get_archive_filepath())) {
         WP_CLI::success(__('Backup Complete: ', 'backupwordpress') . $hm_backup->get_archive_filepath());
     } else {
         WP_CLI::error(__('Backup Failed', 'backupwordpress'));
     }
 }
 /**
  * Setup the schedule object
  * Loads the options from the database and populates properties
  *
  * @param string $id
  * @throws Exception
  */
 public function __construct($id)
 {
     // Verify the schedule id
     if (!is_string($id) || !trim($id)) {
         throw new Exception('Argument 1 for ' . __METHOD__ . ' must be a non empty string');
     }
     // Setup HM Backup
     parent::__construct();
     // Store id for later
     $this->id = $id;
     // Load the options
     $this->options = array_filter((array) get_option('hmbkp_schedule_' . $this->get_id()));
     // Some properties can be overridden with defines
     if (defined('HMBKP_ROOT') && HMBKP_ROOT) {
         $this->set_root(HMBKP_ROOT);
     }
     if (defined('HMBKP_PATH') && HMBKP_PATH) {
         $this->set_path(HMBKP_PATH);
     }
     if (defined('HMBKP_EXCLUDE') && HMBKP_EXCLUDE) {
         parent::set_excludes(HMBKP_EXCLUDE, true);
     }
     parent::set_excludes($this->default_excludes(), true);
     if (defined('HMBKP_MYSQLDUMP_PATH')) {
         $this->set_mysqldump_command_path(HMBKP_MYSQLDUMP_PATH);
     }
     if (defined('HMBKP_ZIP_PATH')) {
         $this->set_zip_command_path(HMBKP_ZIP_PATH);
     }
     if (defined('HMBKP_ZIP_PATH') && HMBKP_ZIP_PATH === 'PclZip' && ($this->skip_zip_archive = true)) {
         $this->set_zip_command_path(false);
     }
     if (defined('HMBKP_SCHEDULE_START_TIME') && strtotime('HMBKP_SCHEDULE_START_TIME')) {
         $this->set_schedule_start_time(strtotime('HMBKP_SCHEDULE_START_TIME'));
     }
     // Set the path - TODO remove external function dependancy
     $this->set_path(hmbkp_path());
     // Set the archive filename to site name + schedule slug + date
     $this->set_archive_filename(implode('-', array(sanitize_title(str_ireplace(array('http://', 'https://', 'www'), '', home_url())), $this->get_id(), $this->get_type(), date('Y-m-d-H-i-s', current_time('timestamp')))) . '.zip');
     $this->set_database_dump_filename(implode('-', array(sanitize_title(str_ireplace(array('http://', 'https://', 'www'), '', home_url())), $this->get_id(), $this->get_type(), date('Y-m-d-H-i-s', current_time('timestamp')))) . '.sql');
     // Setup the schedule if it isn't set
     if (!$this->is_cron_scheduled() && $this->get_reoccurrence() !== 'manually') {
         $this->schedule();
     }
 }
 /**
  * Cleanup the backup file and tmp directory
  * after every test
  *
  */
 public function tearDown()
 {
     hmbkp_rmdirtree(hmbkp_path());
     unset($this->backup);
     HM\BackUpWordPress\Path::get_instance()->reset_path();
 }
Exemple #16
0
<?php 
} else {
    if (!hmbkp_get_database_only() && !hmbkp_get_files_only()) {
        $what_to_backup = '<code>' . __('database', 'hmbkp') . '</code> ' . __('&amp;', 'hmbkp') . ' <code>' . __('files', 'hmbkp') . '</code>';
    } elseif (hmbkp_get_database_only()) {
        $what_to_backup = '<code>' . __('database', 'hmbkp') . '</code>';
    } else {
        $what_to_backup = '<code>' . __('files', 'hmbkp') . '</code>';
    }
    ?>

    	<?php 
    $offset = current_time('timestamp') - time();
    $schedules = wp_get_schedules();
    $schedule = $schedules[wp_get_schedule('hmbkp_schedule_backup_hook')]['display'];
    printf(__('Your %s will be automatically backed up <code>%s</code>. The next backup will occur at %s on %s and be saved to %s.', 'hmbkp'), $what_to_backup, $schedule, '<code>' . date_i18n(get_option('time_format'), wp_next_scheduled('hmbkp_schedule_backup_hook') + $offset) . '</code>', '<code title="' . sprintf(__('It\'s currently %s', 'hmbkp'), date_i18n(get_option('time_format'))) . '">' . date_i18n(get_option('date_format'), wp_next_scheduled('hmbkp_schedule_backup_hook') + $offset) . '</code>', '<code>' . hmbkp_path() . '</code>');
    ?>

<?php 
}
?>

</p>

<p>&#10003; <span class="hmbkp_estimated-size"><?php 
printf(__('Your site is %s. Backups will be compressed and should be smaller than this.', 'hmbkp'), get_transient('hmbkp_estimated_filesize') ? '<code>' . hmbkp_calculate() . '</code>' : '<code class="calculate">' . __('Calculating Size...', 'hmbkp') . '</code>');
?>
</span></p>

<?php 
if (hmbkp_get_email_address()) {
Exemple #17
0
/**
 * Remove any non backup.zip files from the backups dir.
 *
 * @return void
 */
function hmbkp_cleanup()
{
    if (defined('HMBKP_PATH') && HMBKP_PATH) {
        return;
    }
    $hmbkp_path = hmbkp_path();
    if (!is_dir($hmbkp_path)) {
        return;
    }
    if ($handle = opendir($hmbkp_path)) {
        while (false !== ($file = readdir($handle))) {
            if (!in_array($file, array('.', '..', 'index.html')) && pathinfo($file, PATHINFO_EXTENSION) !== 'zip') {
                hmbkp_rmdirtree(trailingslashit($hmbkp_path) . $file);
            }
        }
        closedir($handle);
    }
}
Exemple #18
0
    case 'hmbkp_weekly':
        $reoccurrence = sprintf(__('weekly on %1$s at %2$s', 'hmbkp'), '<span ' . $next_backup . '>' . esc_html($day) . '</span>', '<span>' . esc_html(date_i18n(get_option('time_format'), $schedule->get_next_occurrence(false))) . '</span>');
        break;
    case 'hmbkp_fortnightly':
        $reoccurrence = sprintf(__('fortnightly on %1$s at %2$s', 'hmbkp'), '<span ' . $next_backup . '>' . $day . '</span>', '<span>' . esc_html(date_i18n(get_option('time_format'), $schedule->get_next_occurrence(false))) . '</span>');
        break;
    case 'hmbkp_monthly':
        $reoccurrence = sprintf(__('on the %1$s of each month at %2$s', 'hmbkp'), '<span ' . $next_backup . '>' . esc_html(date_i18n('jS', $schedule->get_next_occurrence(false))) . '</span>', '<span>' . esc_html(date_i18n(get_option('time_format'), $schedule->get_next_occurrence(false))) . '</span>');
        break;
    case 'manually':
        $reoccurrence = __('manually', 'hmbkp');
        break;
    default:
        $schedule->set_reoccurrence('manually');
}
$server = '<span title="' . esc_attr(hmbkp_path()) . '">' . __('this server', 'hmbkp') . '</span>';
// Backup to keep
switch ($schedule->get_max_backups()) {
    case 1:
        $backup_to_keep = sprintf(__('store only the last backup on %s', 'hmbkp'), $server);
        break;
    case 0:
        $backup_to_keep = sprintf(__('don\'t store any backups on %s', 'hmbkp'), $server);
        break;
    default:
        $backup_to_keep = sprintf(__('store only the last %1$s backups on %2$s', 'hmbkp'), esc_html($schedule->get_max_backups()), $server);
}
$email_msg = '';
foreach (HMBKP_Services::get_services($schedule) as $file => $service) {
    if ('Email' == $service->name) {
        $email_msg = wp_kses_post($service->display());
        break;
    case 'manually':
        $reoccurrence = __('manually', 'backupwordpress');
        break;
    default:
        $schedule->set_reoccurrence('manually');
}
$server = '<span title="' . esc_attr(hmbkp_path()) . '">' . __('this server', 'backupwordpress') . '</span>';
$server = '<code>' . esc_attr(str_replace($schedule->get_home_path(), '', hmbkp_path())) . '</code>';
// Backup to keep
switch ($schedule->get_max_backups()) {
    case 1:
        $backup_to_keep = sprintf(__('store the most recent backup in %s', 'backupwordpress'), $server);
        break;
    case 0:
        $backup_to_keep = sprintf(__('don\'t store any backups in on this server', 'backupwordpress'), hmbkp_path());
        break;
    default:
        $backup_to_keep = sprintf(__('store the last %1$s backups in %2$s', 'backupwordpress'), esc_html($schedule->get_max_backups()), $server);
}
$email_msg = $services = '';
foreach (HMBKP_Services::get_services($schedule) as $file => $service) {
    if ('Email' === $service->name) {
        $email_msg = wp_kses_post($service->display());
    } elseif ($service->is_service_active()) {
        $services[] = esc_html($service->display());
    }
}
if (!empty($services) && count($services) > 1) {
    $services[count($services) - 2] .= ' & ' . $services[count($services) - 1];
    array_pop($services);
Exemple #20
0
/**
 * Cancels a running backup then redirect back to the backups page
 */
function hmbkp_request_cancel_backup()
{
    check_admin_referer('hmbkp_request_cancel_backup', 'hmbkp-request_cancel_backup_nonce');
    $schedule = new HMBKP_Scheduled_Backup(sanitize_text_field(urldecode($_GET['hmbkp_schedule_id'])));
    // Delete the running backup
    if ($schedule->get_running_backup_filename() && file_exists(trailingslashit(hmbkp_path()) . $schedule->get_running_backup_filename())) {
        unlink(trailingslashit(hmbkp_path()) . $schedule->get_running_backup_filename());
    }
    if ($schedule->get_schedule_running_path() && file_exists($schedule->get_schedule_running_path())) {
        unlink($schedule->get_schedule_running_path());
    }
    HMBKP_Path::get_instance()->cleanup();
    wp_safe_redirect(hmbkp_get_settings_url(), 303);
    die;
}
    function get_excluded($browse_dir = null)
    {
        $schedule_id = $this->check_schedule();
        $schedule = new HM\BackUpWordPress\Scheduled_Backup(sanitize_text_field(urldecode($schedule_id)));
        ob_start();
        ?>
    <div class="hmbkp-exclude-settings">

	<?php 
        if ($schedule->get_excludes()) {
            ?>

		<h3>
			<?php 
            _e('Currently Excluded', 'backupwordpress');
            ?>
		</h3>

		<p><?php 
            _e('We automatically detect and ignore common <abbr title="Version Control Systems">VCS</abbr> folders and other backup plugin folders.', 'backupwordpress');
            ?>
</p>

		<table class="widefat">

			<tbody>

			<?php 
            foreach (array_diff($schedule->get_excludes(), $schedule->backup->default_excludes()) as $key => $exclude) {
                $exclude_path = new SplFileInfo(trailingslashit($schedule->backup->get_root()) . ltrim(str_ireplace($schedule->backup->get_root(), '', $exclude), '/'));
                ?>

				<tr>

					<th scope="row">

						<?php 
                if ($exclude_path->isFile()) {
                    ?>

							<div class="dashicons dashicons-media-default"></div>

						<?php 
                } elseif ($exclude_path->isDir()) {
                    ?>

							<div class="dashicons dashicons-portfolio"></div>

						<?php 
                }
                ?>

					</th>

					<td>
						<code><?php 
                echo esc_html(str_ireplace($schedule->backup->get_root(), '', $exclude));
                ?>
</code>

					</td>

					<td>

						<?php 
                if (in_array($exclude, $schedule->backup->default_excludes()) || hmbkp_path() === untrailingslashit($exclude)) {
                    ?>

							<?php 
                    _e('Default rule', 'backupwordpress');
                    ?>

						<?php 
                } elseif (defined('HMBKP_EXCLUDE') && false !== strpos(HMBKP_EXCLUDE, $exclude)) {
                    ?>

							<?php 
                    _e('Defined in wp-config.php', 'backupwordpress');
                    ?>

						<?php 
                } else {
                    ?>

							<a href="#" onclick="event.preventDefault(); mainwp_backupwp_remove_exclude_rule('<?php 
                    echo $exclude;
                    ?>
', this);"  class="delete-action"><?php 
                    _e('Stop excluding', 'backupwordpress');
                    ?>
</a>

						<?php 
                }
                ?>

					</td>

				</tr>

			<?php 
            }
            ?>

			</tbody>

		</table>

	<?php 
        }
        ?>

	<h3 id="directory-listing"><?php 
        _e('Directory Listing', 'backupwordpress');
        ?>
</h3>

	<p><?php 
        _e('Here\'s a directory listing of all files on your site, you can browse through and exclude files or folders that you don\'t want included in your backup.', 'backupwordpress');
        ?>
</p>

	<?php 
        // The directory to display
        $directory = $schedule->backup->get_root();
        if (isset($browse_dir)) {
            $untrusted_directory = urldecode($browse_dir);
            // Only allow real sub directories of the site root to be browsed
            if (false !== strpos($untrusted_directory, $schedule->backup->get_root()) && is_dir($untrusted_directory)) {
                $directory = $untrusted_directory;
            }
        }
        $exclude_string = $schedule->backup->exclude_string('regex');
        // Kick off a recursive filesize scan
        $files = $schedule->list_directory_by_total_filesize($directory);
        if ($files) {
            ?>

            <table class="widefat">
                <thead>
                <tr>
                        <th></th>
                        <th scope="col"><?php 
            _e('Name', 'backupwordpress');
            ?>
</th>
                        <th scope="col" class="column-format"><?php 
            _e('Size', 'backupwordpress');
            ?>
</th>
                        <th scope="col" class="column-format"><?php 
            _e('Permissions', 'backupwordpress');
            ?>
</th>
                        <th scope="col" class="column-format"><?php 
            _e('Type', 'backupwordpress');
            ?>
</th>
                        <th scope="col" class="column-format"><?php 
            _e('Status', 'backupwordpress');
            ?>
</th>
                </tr>

                <tr>

                        <th scope="row">
                                <div class="dashicons dashicons-admin-home"></div>
                        </th>

                        <th scope="col">

                                <?php 
            if ($schedule->backup->get_root() !== $directory) {
                // echo esc_url( remove_query_arg( 'hmbkp_directory_browse' ) );
                ?>
                                        <a href="#" onclick="event.preventDefault(); mainwp_backupwp_directory_browse('', this)"><?php 
                echo esc_html($schedule->backup->get_root());
                ?>
</a>
                                        <code>/</code>

                                        <?php 
                $parents = array_filter(explode('/', str_replace(trailingslashit($schedule->backup->get_root()), '', trailingslashit(dirname($directory)))));
                foreach ($parents as $directory_basename) {
                    ?>

                                                <a href="#" onclick="event.preventDefault(); mainwp_backupwp_directory_browse('<?php 
                    echo urlencode(substr($directory, 0, strpos($directory, $directory_basename)) . $directory_basename);
                    ?>
', this)" ><?php 
                    echo esc_html($directory_basename);
                    ?>
</a>
                                                <code>/</code>

                                        <?php 
                }
                ?>

                                        <?php 
                echo esc_html(basename($directory));
                ?>

                                <?php 
            } else {
                ?>

                                        <?php 
                echo esc_html($schedule->backup->get_root());
                ?>

                                <?php 
            }
            ?>

                        </th>

                        <td class="column-filesize">

                                <?php 
            if ($schedule->is_site_size_being_calculated()) {
                ?>

                                        <span class="spinner"></span>

                                <?php 
            } else {
                $root = new SplFileInfo($schedule->backup->get_root());
                $size = $schedule->filesize($root, true);
                if (false !== $size) {
                    $size = size_format($size);
                    if (!$size) {
                        $size = '0 B';
                    }
                    ?>

                                                <code>

                                                        <?php 
                    echo esc_html($size);
                    ?>

                                                        <a class="dashicons dashicons-update"
                                                           href="<?php 
                    echo wp_nonce_url(add_query_arg('hmbkp_recalculate_directory_filesize', urlencode($schedule->backup->get_root())), 'hmbkp-recalculate_directory_filesize');
                    ?>
"><span><?php 
                    _e('Refresh', 'backupwordpress');
                    ?>
</span></a>

                                                </code>


                                        <?php 
                }
                ?>

                                <?php 
            }
            ?>

                        <td>
                                <?php 
            echo esc_html(substr(sprintf('%o', fileperms($schedule->backup->get_root())), -4));
            ?>
                        </td>

                        <td>

                                <?php 
            if (is_link($schedule->backup->get_root())) {
                _e('Symlink', 'backupwordpress');
            } elseif (is_dir($schedule->backup->get_root())) {
                _e('Folder', 'backupwordpress');
            }
            ?>

                        </td>

                        <td></td>

                </tr>

                </thead>

                <tbody>

                <?php 
            foreach ($files as $size => $file) {
                $is_excluded = $is_unreadable = false;
                // Check if the file is excluded
                if ($exclude_string && preg_match('(' . $exclude_string . ')', str_ireplace(trailingslashit($schedule->backup->get_root()), '', HM\BackUpWordPress\Backup::conform_dir($file->getPathname())))) {
                    $is_excluded = true;
                }
                // Skip unreadable files
                if (!@realpath($file->getPathname()) || !$file->isReadable()) {
                    $is_unreadable = true;
                }
                ?>

                        <tr>

                                <td>

                                        <?php 
                if ($is_unreadable) {
                    ?>

                                                <div class="dashicons dashicons-dismiss"></div>

                                        <?php 
                } elseif ($file->isFile()) {
                    ?>

                                                <div class="dashicons dashicons-media-default"></div>

                                        <?php 
                } elseif ($file->isDir()) {
                    ?>

                                                <div class="dashicons dashicons-portfolio"></div>

                                        <?php 
                }
                ?>

                                </td>

                                <td>

                                        <?php 
                if ($is_unreadable) {
                    ?>

                                                <code class="strikethrough"
                                                      title="<?php 
                    echo esc_attr($file->getRealPath());
                    ?>
"><?php 
                    echo esc_html($file->getBasename());
                    ?>
</code>

                                        <?php 
                } elseif ($file->isFile()) {
                    ?>

                                                <code
                                                        title="<?php 
                    echo esc_attr($file->getRealPath());
                    ?>
"><?php 
                    echo esc_html($file->getBasename());
                    ?>
</code>

                                        <?php 
                } elseif ($file->isDir()) {
                    //echo add_query_arg( 'hmbkp_directory_browse', urlencode( $file->getPathname() ) );
                    ?>
                                                <code title="<?php 
                    echo esc_attr($file->getRealPath());
                    ?>
"><a
                                                        href="#" onclick="event.preventDefault(); mainwp_backupwp_directory_browse('<?php 
                    echo urlencode($file->getPathname());
                    ?>
', this)" ><?php 
                    echo esc_html($file->getBasename());
                    ?>
</a></code>

                                        <?php 
                }
                ?>

                                </td>

                                <td class="column-format column-filesize">

                                        <?php 
                if ($file->isDir() && $schedule->is_site_size_being_calculated()) {
                    ?>

                                                <span class="spinner"></span>

                                        <?php 
                } else {
                    $size = $schedule->filesize($file);
                    if (false !== $size) {
                        $size = size_format($size);
                        if (!$size) {
                            $size = '0 B';
                        }
                        ?>

                                                        <code>

                                                                <?php 
                        echo esc_html($size);
                        ?>

                                                                <?php 
                        if ($file->isDir()) {
                            ?>

                                                                        <a title="<?php 
                            _e('Recalculate the size of this directory', 'backupwordpress');
                            ?>
"
                                                                           class="dashicons dashicons-update"
                                                                           href="<?php 
                            echo wp_nonce_url(add_query_arg('hmbkp_recalculate_directory_filesize', urlencode($file->getPathname())), 'hmbkp-recalculate_directory_filesize');
                            ?>
"><span><?php 
                            _e('Refresh', 'backupwordpress');
                            ?>
</span></a>

                                                                <?php 
                        }
                        ?>

                                                        </code>


                                                <?php 
                    } else {
                        ?>

                                                        <code>--</code>

                                                <?php 
                    }
                }
                ?>

                                </td>

                                <td>
                                        <?php 
                echo esc_html(substr(sprintf('%o', $file->getPerms()), -4));
                ?>
                                </td>

                                <td>

                                        <?php 
                if ($file->isLink()) {
                    ?>

                                                <span
                                                        title="<?php 
                    echo esc_attr($file->GetRealPath());
                    ?>
"><?php 
                    _e('Symlink', 'backupwordpress');
                    ?>
</span>

                                        <?php 
                } elseif ($file->isDir()) {
                    _e('Folder', 'backupwordpress');
                } else {
                    _e('File', 'backupwordpress');
                }
                ?>

                                </td>

                                <td class="column-format">

                                        <?php 
                if ($is_unreadable) {
                    ?>

                                                <strong
                                                        title="<?php 
                    _e('Unreadable files won\'t be backed up.', 'backupwordpress');
                    ?>
"><?php 
                    _e('Unreadable', 'backupwordpress');
                    ?>
</strong>

                                        <?php 
                } elseif ($is_excluded) {
                    ?>

                                                <strong><?php 
                    _e('Excluded', 'backupwordpress');
                    ?>
</strong>

                                        <?php 
                } else {
                    $exclude_path = $file->getPathname();
                    // Excluded directories need to be trailingslashed
                    if ($file->isDir()) {
                        $exclude_path = trailingslashit($file->getPathname());
                    }
                    ?>

                                                <a href="#" onclick="event.preventDefault(); mainwp_backupwp_exclude_add_rule('<?php 
                    echo urlencode($exclude_path);
                    ?>
', this)"
                                                   class="button-secondary"><?php 
                    _e('Exclude &rarr;', 'backupwordpress');
                    ?>
</a>

                                        <?php 
                }
                ?>

                                </td>

                        </tr>

                <?php 
            }
            ?>
                </tbody>
        </table>

                <?php 
        }
        ?>

                <p class="submit">
                        <a href="#" onclick="event.preventDefault(); mainwp_backupwp_edit_exclude_done()"
                           class="button-primary"><?php 
        _e('Done', 'backupwordpress');
        ?>
</a>
                </p>

        </div>

        <?php 
        $output = ob_get_clean();
        $information['e'] = $output;
        return $information;
    }
        ?>

					</th>

					<td>
						<code><?php 
        echo esc_html(str_ireplace($schedule->backup->get_root(), '', $exclude));
        ?>
</code>

					</td>

					<td>

						<?php 
        if (in_array($exclude, $schedule->backup->default_excludes()) || hmbkp_path() === untrailingslashit($exclude)) {
            ?>

							<?php 
            _e('Default rule', 'backupwordpress');
            ?>

						<?php 
        } elseif (defined('HMBKP_EXCLUDE') && false !== strpos(HMBKP_EXCLUDE, $exclude)) {
            ?>

							<?php 
            _e('Defined in wp-config.php', 'backupwordpress');
            ?>

						<?php 
Exemple #23
0
 /**
  * Get the directory backups are saved to
  *
  * @return string
  */
 public function get_path()
 {
     if (empty($this->path)) {
         $this->set_path(self::conform_dir(hmbkp_path()));
     }
     return $this->path;
 }
<?php

if (!defined('HMBKP_PLUGIN_PATH')) {
    define('HMBKP_PLUGIN_PATH', plugin_dir_path(__FILE__));
}
// Load the schedules
require_once HMBKP_PLUGIN_PATH . 'hm-backup/hm-backup.php';
require_once HMBKP_PLUGIN_PATH . 'classes/class-services.php';
require_once HMBKP_PLUGIN_PATH . 'classes/class-schedule.php';
require_once HMBKP_PLUGIN_PATH . 'classes/class-schedules.php';
require_once HMBKP_PLUGIN_PATH . 'functions/core.php';
$schedules = HMBKP_Schedules::get_instance();
// Cancel all the schedules and delete all the backups
foreach ($schedules->get_schedules() as $schedule) {
    $schedule->cancel(true);
}
// Remove the backups directory
hmbkp_rmdirtree(hmbkp_path());
// Remove all the options
foreach (array('hmbkp_enable_support', 'hmbkp_plugin_version', 'hmbkp_path', 'hmbkp_default_path', 'hmbkp_upsell') as $option) {
    delete_option($option);
}
Exemple #25
0
/**
 * Check if a backup is possible with regards to file
 * permissions etc.
 *
 * @return bool
 */
function hmbkp_possible()
{
    if (!wp_is_writable(hmbkp_path()) || !is_dir(hmbkp_path())) {
        return false;
    }
    $test_backup = new HM\BackUpWordPress\Backup();
    if (!is_readable($test_backup->get_root())) {
        return false;
    }
    return true;
}
 function hmbkp_custom_path_writable_notice()
 {
     echo '<div id="hmbkp-warning" class="updated fade"><p><strong>' . __('BackUpWordPress has detected a problem.', 'hmbkp') . '</strong> ' . sprintf(__('Your custom backups directory %s isn\'t writable, new backups will be saved to %s instead.', 'hmbkp'), '<code>' . HMBKP_PATH . '</code>', '<code>' . hmbkp_path() . '</code>') . '</p></div>';
 }
Exemple #27
0
/**
 * Load the backup warnings file
 *
 * @return string
 */
function hmbkp_backup_warnings()
{
    if (!file_exists(hmbkp_path() . '/.backup_warnings')) {
        return '';
    }
    return file_get_contents(hmbkp_path() . '/.backup_warnings');
}
Exemple #28
0
			<td>

				<?php 
if (defined('HMBKP_PATH')) {
    ?>
					<p><?php 
    printf(__('You\'ve set it to: %s', 'backupwordpress'), '<code>' . esc_html(HMBKP_PATH) . '</code>');
    ?>
</p>
				<?php 
}
?>

				<p><?php 
printf(__('The path to folder you would like to store your backup files in, defaults to %s.', 'backupwordpress'), '<code>' . esc_html(hmbkp_path()) . '</code>');
?>
 <?php 
_e('e.g.', 'backupwordpress');
?>
 <code>define( 'HMBKP_PATH', '/home/willmot/backups' );</code></p>

			</td>

		</tr>

		<tr<?php 
if (defined('HMBKP_MYSQLDUMP_PATH')) {
    ?>
 class="hmbkp_active"<?php 
}
 /**
  * If the HMBKP_PATH constant is defined and the new directory is writable then everything should be moved there
  *
  * @access public
  * @return void
  */
 public function testUnWritableDefinedBackupPath()
 {
     $this->assertEquals(hmbkp_path(), HMBKP_PATH);
     $this->backup->backup();
     $this->assertFileExists($this->backup->get_archive_filepath());
     chmod($this->custom_path, 0555);
     if (is_writable($this->custom_path)) {
         $this->markTestSkipped('The custom path was still writable');
     }
     hmbkp_constant_changes();
     $this->assertEquals(hmbkp_path(), hmbkp_path_default());
     $this->assertFileExists(str_replace($this->backup->get_path(), hmbkp_path_default(), $this->backup->get_archive_filepath()));
     // They should both exist because we didn't have permission to remove the old file
     $this->assertFileExists($this->backup->get_archive_filepath());
 }
Exemple #30
0
/**
 * Cancels a running backup then redirect
 * back to the backups page
 */
function hmbkp_request_cancel_backup()
{
    if (!isset($_GET['action']) || $_GET['action'] !== 'hmbkp_cancel') {
        return;
    }
    $schedule = new HMBKP_Scheduled_Backup(sanitize_text_field(urldecode($_GET['hmbkp_schedule_id'])));
    // Delete the running backup
    if ($schedule->get_running_backup_filename() && file_exists(trailingslashit(hmbkp_path()) . $schedule->get_running_backup_filename())) {
        unlink(trailingslashit(hmbkp_path()) . $schedule->get_running_backup_filename());
    }
    hmbkp_cleanup();
    wp_redirect(remove_query_arg(array('action')), 303);
    die;
}