Ejemplo n.º 1
0
/**
 * Display a html list of files
 *
 * @param HMBKP_Scheduled_Backup $schedule
 * @param mixed                  $excludes    (default: null)
 * @param string                 $file_method (default: 'get_included_files')
 * @return void
 */
function hmbkp_file_list(HMBKP_Scheduled_Backup $schedule, $excludes = null, $file_method = 'get_included_files')
{
    if (!is_null($excludes)) {
        $schedule->set_excludes($excludes);
    }
    $exclude_string = $schedule->exclude_string('regex');
    ?>

	<ul class="hmbkp_file_list code">

		<?php 
    foreach ($schedule->get_files() as $file) {
        if (!is_null($excludes) && strpos($file, str_ireplace($schedule->get_root(), '', $schedule->get_path())) !== false) {
            continue;
        }
        // Skip dot files, they should only exist on versions of PHP between 5.2.11 -> 5.3
        if (method_exists($file, 'isDot') && $file->isDot()) {
            continue;
        }
        // Show only unreadable files
        if ($file_method === 'get_unreadable_files' && @realpath($file->getPathname()) && $file->isReadable()) {
            continue;
        } elseif ($file_method !== 'get_unreadable_files' && (!@realpath($file->getPathname()) || !$file->isReadable())) {
            continue;
        }
        // Show only included files
        if ($file_method === 'get_included_files') {
            if ($exclude_string && preg_match('(' . $exclude_string . ')', str_ireplace(trailingslashit($schedule->get_root()), '', HM_Backup::conform_dir($file->getPathname())))) {
                continue;
            }
        }
        // Show only excluded files
        if ($file_method === 'get_excluded_files') {
            if (!$exclude_string || !preg_match('(' . $exclude_string . ')', str_ireplace(trailingslashit($schedule->get_root()), '', HM_Backup::conform_dir($file->getPathname())))) {
                continue;
            }
        }
        if (@realpath($file->getPathname()) && !$file->isReadable() && $file->isDir()) {
            ?>

				<li title="<?php 
            echo esc_attr(HM_Backup::conform_dir(trailingslashit($file->getPathName())));
            ?>
"><?php 
            echo esc_html(ltrim(trailingslashit(str_ireplace(HM_Backup::conform_dir(trailingslashit($schedule->get_root())), '', HM_Backup::conform_dir($file->getPathName()))), '/'));
            ?>
</li>

			<?php 
        } else {
            ?>

				<li title="<?php 
            echo esc_attr(HM_Backup::conform_dir($file->getPathName()));
            ?>
"><?php 
            echo esc_html(ltrim(str_ireplace(HM_Backup::conform_dir(trailingslashit($schedule->get_root())), '', HM_Backup::conform_dir($file->getPathName())), '/'));
            ?>
</li>

			<?php 
        }
    }
    ?>

	</ul>

<?php 
}
Ejemplo n.º 2
0
/**
 * Add an exclude rule
 *
 * @access public
 * @return void
 */
function hmbkp_add_exclude_rule()
{
    check_admin_referer('hmbkp-add-exclude-rule', 'hmbkp-add-exclude-rule-nonce');
    if (!isset($_GET['hmbkp_exclude_pathname'])) {
        return;
    }
    $schedule = new HMBKP_Scheduled_Backup(sanitize_text_field($_GET['hmbkp_schedule_id']));
    $exclude_rule = str_ireplace($schedule->get_root(), '', sanitize_text_field($_GET['hmbkp_exclude_pathname']));
    $schedule->set_excludes($exclude_rule, true);
    $schedule->save();
    wp_safe_redirect(wp_get_referer(), '303');
    die;
}
Ejemplo n.º 3
0
 function hmbkp_ba§ckup_root_unreadable_notice()
 {
     $test_backup = new HMBKP_Scheduled_Backup('test_backup');
     echo '<div id="hmbkp-warning" class="updated fade"><p><strong>' . __('BackUpWordPress has detected a problem.', 'hmbkp') . '</strong>' . sprintf(__('Your backup root path %s isn\'t readable.', 'hmbkp'), '<code>' . $test_backup->get_root() . '</code>') . '</p></div>';
 }
Ejemplo n.º 4
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 HMBKP_Scheduled_Backup('test_backup');
    if (!is_readable($test_backup->get_root())) {
        return false;
    }
    return true;
}
Ejemplo n.º 5
0
function hmbkp_set_server_config_notices()
{
    $notices = HMBKP_Notices::get_instance();
    $messages = array();
    if (!HM_Backup::is_shell_exec_available()) {
        $php_user = '******';
        $php_group = '<PHP GROUP>';
    } else {
        $php_user = shell_exec('whoami');
        $groups = explode(' ', shell_exec('groups'));
        $php_group = reset($groups);
    }
    if (!is_dir(hmbkp_path())) {
        $messages[] = sprintf(__('The backups directory can\'t be created because your %1$s directory isn\'t writable, run %2$s or %3$s or create the folder yourself.', 'backupwordpress'), '<code>' . esc_html(dirname(hmbkp_path())) . '</code>', '<code>chown ' . esc_html($php_user) . ':' . esc_html($php_group) . ' ' . esc_html(dirname(hmbkp_path())) . '</code>', '<code>chmod 777 ' . esc_html(dirname(hmbkp_path())) . '</code>');
    }
    if (is_dir(hmbkp_path()) && !wp_is_writable(hmbkp_path())) {
        $messages[] = sprintf(__('Your backups directory isn\'t writable, run %1$s or %2$s or set the permissions yourself.', 'backupwordpress'), '<code>chown -R ' . esc_html($php_user) . ':' . esc_html($php_group) . ' ' . esc_html(hmbkp_path()) . '</code>', '<code>chmod -R 777 ' . esc_html(hmbkp_path()) . '</code>');
    }
    if (HM_Backup::is_safe_mode_active()) {
        $messages[] = sprintf(__('%1$s is running in %2$s, please contact your host and ask them to disable it. BackUpWordPress may not work correctly whilst %3$s is on.', 'backupwordpress'), '<code>PHP</code>', sprintf('<a href="%1$s">%2$s</a>', __('http://php.net/manual/en/features.safe-mode.php', 'backupwordpress'), __('Safe Mode', 'backupwordpress')), '<code>' . __('Safe Mode', 'backupwordpress') . '</code>');
    }
    if (defined('HMBKP_PATH') && HMBKP_PATH) {
        // Suppress open_basedir warning https://bugs.php.net/bug.php?id=53041
        if (!@file_exists(HMBKP_PATH)) {
            $messages[] = sprintf(__('Your custom path does not exist', 'backupwordpress'));
        } elseif (hmbkp_is_restricted_custom_path()) {
            $messages[] = sprintf(__('Your custom path is unreachable due to a restriction set in your PHP configuration (open_basedir)', 'backupwordpress'));
        } else {
            if (!@is_dir(HMBKP_PATH)) {
                $messages[] = sprintf(__('Your custom backups directory %1$s doesn\'t exist and can\'t be created, your backups will be saved to %2$s instead.', 'backupwordpress'), '<code>' . esc_html(HMBKP_PATH) . '</code>', '<code>' . esc_html(hmbkp_path()) . '</code>');
            }
            if (@is_dir(HMBKP_PATH) && !wp_is_writable(HMBKP_PATH)) {
                $messages[] = sprintf(__('Your custom backups directory %1$s isn\'t writable, new backups will be saved to %2$s instead.', 'backupwordpress'), '<code>' . esc_html(HMBKP_PATH) . '</code>', '<code>' . esc_html(hmbkp_path()) . '</code>');
            }
        }
    }
    $test_backup = new HMBKP_Scheduled_Backup('test_backup');
    if (!is_readable($test_backup->get_root())) {
        $messages[] = sprintf(__('Your site root path %s isn\'t readable.', 'backupwordpress'), '<code>' . $test_backup->get_root() . '</code>');
    }
    if (count($messages) > 0) {
        $notices->set_notices('server_config', $messages, false);
    }
}
Ejemplo n.º 6
0
/**
 *
 * @param null $pathname
 */
function hmbkp_recalculate_directory_filesize($pathname = null)
{
    if (!$pathname && (!isset($_GET['hmbkp_recalculate_directory_filesize']) || !check_admin_referer('hmbkp-recalculate_directory_filesize'))) {
        return;
    }
    $schedule = new HMBKP_Scheduled_Backup(sanitize_text_field($_GET['hmbkp_schedule_id']));
    if (!$pathname) {
        $directory = sanitize_text_field($_GET['hmbkp_recalculate_directory_filesize']);
    } else {
        $directory = $pathname;
    }
    // Delete the cached directory size
    // TODO should use $schedule->get_transient_key
    delete_transient($schedule->get_transient_key($directory));
    $handle = opendir($directory);
    while ($file_handle = readdir($handle)) {
        // Ignore current dir and containing dir
        if ($file_handle === '.' || $file_handle === '..') {
            continue;
        }
        $file = HM_Backup::conform_dir(trailingslashit($directory) . $file_handle);
        // Delete all sub directories
        if (is_dir($file)) {
            delete_transient($schedule->get_transient_key($file));
            hmbkp_recalculate_directory_filesize($file);
        }
    }
    closedir($handle);
    $parent_directory = dirname($directory);
    // Delete the cached filesize of all parents as well
    while ($schedule->get_root() !== $parent_directory) {
        delete_transient($schedule->get_transient_key($parent_directory));
        $parent_directory = dirname($parent_directory);
    }
    if (!$pathname) {
        $url = add_query_arg(array('action' => 'hmbkp_edit_schedule', 'hmbkp_panel' => 'hmbkp_edit_schedule_excludes'), hmbkp_get_settings_url());
        if (isset($_GET['hmbkp_directory_browse'])) {
            $url = add_query_arg('hmbkp_directory_browse', sanitize_text_field($_GET['hmbkp_directory_browse']), $url);
        }
        wp_safe_redirect($url, '303');
        die;
    }
}