コード例 #1
0
 public function tearDown()
 {
     if (file_exists(Path::get_path() . '/.files')) {
         unlink(Path::get_path() . '/.files');
     }
     $this->cleanup_test_data();
     delete_transient('hmbkp_directory_filesizes_running');
 }
コード例 #2
0
ファイル: Template.php プロジェクト: marious/php-cms
 public static function highlight($nav)
 {
     if (!empty(Path::get_path()['call_parts'][0])) {
         if (Path::get_path()['call_parts'][0] == $nav) {
             return 'active';
         }
     } else {
         if ($nav == 'index') {
             return 'active';
         }
     }
 }
コード例 #3
0
 /**
  * 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.
  *
  * [--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'));
     });
     if (!empty($assoc_args['destination'])) {
         Path::get_instance()->set_path($assoc_args['destination']);
     }
     Path::get_instance()->cleanup();
     if (!empty($assoc_args['root'])) {
         Path::get_instance()->set_root($assoc_args['root']);
     }
     if (!is_dir(Path::get_path())) {
         \WP_CLI::error(__('Invalid backup path', 'backupwordpress'));
         return false;
     }
     if (!is_dir(Path::get_root()) || !is_readable(Path::get_root())) {
         \WP_CLI::error(__('Invalid root path', 'backupwordpress'));
         return false;
     }
     $filename = 'backup.zip';
     if (isset($assoc_args['archive_filename'])) {
         $filename = $assoc_args['archive_filename'];
     }
     $hm_backup = new Backup($filename);
     if (!empty($assoc_args['files_only'])) {
         $hm_backup->set_type('file');
     }
     if (!empty($assoc_args['database_only'])) {
         $hm_backup->set_type('database');
     }
     if (!empty($assoc_args['excludes'])) {
         $hm_backup->set_excludes($assoc_args['excludes']);
     }
     $hm_backup->run();
     if (file_exists($hm_backup->get_backup_filepath())) {
         \WP_CLI::success(__('Backup Complete: ', 'backupwordpress') . $hm_backup->get_backup_filepath());
     } else {
         \WP_CLI::error(__('Backup Failed', 'backupwordpress'));
     }
 }
コード例 #4
0
ファイル: Category.php プロジェクト: marious/php-cms
 public static function control()
 {
     $view = Path::get_path()['call_parts'][0];
     $addUrl = HOST_NAME . 'admin/' . $view . '/add';
     $editUrl = HOST_NAME . 'admin/' . $view . '/edit/';
     $deleteUrl = HOST_NAME . 'admin/' . $view . '/delete/';
     $allCategories = self::read("SELECT * FROM categories", PDO::FETCH_CLASS, __CLASS__);
     $table = '<a href="' . $addUrl . '" class="add-link">+ Add New Category</a>';
     $table .= '<table class="admin-table">
                 <tr>
                     <th width="3%">#</th>
                     <th>Category Name</th>
                     <th width="10%" colspan="2">Control</th>
                 </tr>
                 ';
     if ($allCategories != false) {
         if (is_object($allCategories)) {
             $table .= '<tr>
                         <td>' . $allCategories->id . '</td>
                          <td>' . $allCategories->name . '</td>
                          <td class="button">
                             <a href="' . $editUrl . $allCategories->id . '"><i class="fa fa-edit"></i></a>
                             <a href="' . $deleteUrl . $allCategories->id . '" class="delete"><i class="fa fa-trash-o"></i></a>
                          </td>
                     </tr>';
         } else {
             foreach ($allCategories as $category) {
                 $table .= '<tr>
                         <td>' . $category->id . '</td>
                          <td>' . $category->name . '</td>
                          <td class="button">
                             <a href="' . $editUrl . $category->id . '"><i class="fa fa-edit"></i></a>
                             <a href="' . $deleteUrl . $category->id . '" class="delete"><i class="fa fa-trash-o"></i></a>
                          </td>
                     </tr>';
             }
         }
     } else {
         $table .= '<tr><td colspan="4">No Categories Found</td></tr>';
     }
     $table .= '</table>';
     return $table;
 }
コード例 #5
0
ファイル: User.php プロジェクト: marious/php-cms
 public static function control()
 {
     $view = Path::get_path()['call_parts'][0];
     $editUrl = HOST_NAME . 'admin/' . $view . '/edit/';
     $deleteUrl = HOST_NAME . 'admin/' . $view . '/delete/';
     $users = self::read("SELECT * FROM Users WHERE id != " . User::theUser()->id, PDO::FETCH_CLASS, __CLASS__);
     $table = '<table class="admin-table">
                 <tr>
                     <th width="3%">#</th>
                     <th>Username</th>
                     <th width="10%" colspan="2">Control</th>
                 </tr>
                 ';
     if ($users != false) {
         if (is_object($users)) {
             $table .= '<tr>
                         <td>' . $users->id . '</td>
                          <td>' . $users->username . '</td>
                          <td class="button">
                             <a href="' . $editUrl . $users->id . '"><i class="fa fa-edit"></i></a>
                             <a href="' . $deleteUrl . $users->id . '" class="delete"><i class="fa fa-trash-o"></i></a>
                          </td>
                     </tr>';
         } else {
             foreach ($users as $item) {
                 $table .= '<tr>
                         <td>' . $item->id . '</td>
                          <td>' . $item->username . '</td>
                          <td class="button">
                             <a href="' . $editUrl . $item->id . '"><i class="fa fa-edit"></i></a>
                             <a href="' . $deleteUrl . $item->username . '" class="delete"><i class="fa fa-trash-o"></i></a>
                          </td>
                     </tr>';
             }
         }
     } else {
         $table .= '<tr><td colspan="4">No User Found</td></tr>';
     }
     $table .= '</table>';
     return $table;
 }
コード例 #6
0
 public function backup_database()
 {
     if ($this->status) {
         $this->status->set_status(__('Backing up database...', 'backupwordpress'));
     }
     $database_backup_engines = apply_filters('hmbkp_database_backup_engines', array(new Mysqldump_Database_Backup_Engine(), new IMysqldump_Database_Backup_Engine()));
     // Set the file backup engine settings
     if ($this->database_dump_filename) {
         foreach ($database_backup_engines as &$backup_engine) {
             $backup_engine->set_backup_filename($this->database_dump_filename);
         }
     }
     // Dump the database
     $database_dump = $this->perform_backup($database_backup_engines);
     if (is_a($database_dump, __NAMESPACE__ . '\\Backup_Engine')) {
         $this->database_dump_filepath = $database_dump->get_backup_filepath();
     }
     // Fire up the file backup engines
     $file_backup_engines = apply_filters('hmbkp_file_backup_engines', array(new Zip_File_Backup_Engine(), new Zip_Archive_File_Backup_Engine()));
     // Set the file backup engine settings
     foreach ($file_backup_engines as &$backup_engine) {
         $backup_engine->set_backup_filename($this->backup_filename);
         $backup_engine->set_excludes(new Excludes(array('*.zip', 'index.html', '.htaccess', '.*-running')));
     }
     // Zip up the database dump
     $root = Path::get_root();
     Path::get_instance()->set_root(Path::get_path());
     $file_backup = $this->perform_backup($file_backup_engines);
     Path::get_instance()->set_root($root);
     if (is_a($file_backup, __NAMESPACE__ . '\\Backup_Engine')) {
         $this->backup_filepath = $file_backup->get_backup_filepath();
     }
     // Delete the Database Backup now that we've zipped it up
     if (file_exists($this->database_dump_filepath)) {
         unlink($this->database_dump_filepath);
     }
 }
コード例 #7
0
 /**
  * Get the user defined excludes.
  *
  * @return array The array of excludes.
  */
 public function get_user_excludes()
 {
     $excludes = $this->excludes;
     // If path() is inside root(), exclude it.
     if (strpos(Path::get_path(), Path::get_root()) !== false && Path::get_root() !== Path::get_path()) {
         array_unshift($excludes, trailingslashit(Path::get_path()));
     }
     return $this->normalize($excludes);
 }
コード例 #8
0
ファイル: actions.php プロジェクト: crazyyy/bessarabia
/**
 *
 * @param null
 */
function recalculate_directory_filesize()
{
    if (!isset($_GET['hmbkp_recalculate_directory_filesize']) || !check_admin_referer('hmbkp-recalculate_directory_filesize')) {
        return;
    }
    // Delete the cached directory size
    @unlink(trailingslashit(Path::get_path()) . '.files');
    $url = add_query_arg(array('action' => 'hmbkp_edit_schedule', 'hmbkp_panel' => 'hmbkp_edit_schedule_excludes'), 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;
}
コード例 #9
0
ファイル: interface.php プロジェクト: domalexxx/nashvancouver
function set_server_config_notices()
{
    $notices = Notices::get_instance();
    $messages = array();
    if (!is_dir(Path::get_path())) {
        $messages[] = sprintf(__('The backups directory can\'t be created because your %s directory isn\'t writable. Please create the folder manually.', 'backupwordpress'), '<code>' . esc_html(dirname(Path::get_path())) . '</code>');
    }
    if (is_dir(Path::get_path()) && !wp_is_writable(Path::get_path())) {
        $messages[] = __('The backups directory isn\'t writable. Please fix the permissions.', 'backupwordpress');
    }
    if (Backup_Utilities::is_safe_mode_on()) {
        $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 (!path_in_php_open_basedir(HMBKP_PATH)) {
            $messages[] = sprintf(__('Your server has an %1$s restriction in effect and your custom backups directory (%2$s) is not within the allowed path(s): (%3$s).', 'backupwordpress'), '<code>open_basedir</code>', '<code>' . esc_html(HMBKP_PATH) . '</code>', '<code>' . esc_html(@ini_get('open_basedir')) . '</code>');
        } elseif (!file_exists(HMBKP_PATH)) {
            $messages[] = sprintf(__('Your custom path does not exist', '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(Path::get_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(Path::get_path()) . '</code>');
            }
        }
    }
    if (!is_readable(Path::get_root())) {
        $messages[] = sprintf(__('Your site root path %s isn\'t readable.', 'backupwordpress'), '<code>' . Path::get_root() . '</code>');
    }
    if (!Requirement_Mysqldump_Command_Path::test() && !Requirement_PDO::test()) {
        $messages[] = sprintf(__('Your database cannot be backed up because your server doesn\'t support %1$s or %2$s. Please contact your host and ask them to enable them.', 'backupwordpress'), '<code>mysqldump</code>', '<code>PDO</code>');
    }
    if (count($messages) > 0) {
        $notices->set_notices('server_config', $messages, false);
    }
}
コード例 #10
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 the folder you would like to store your backup files in, defaults to %s.', 'backupwordpress'), '<code>' . esc_html(Path::get_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 
}
 /**
  * Get the path to the backup running file that stores the running backup status
  *
  * @return string
  */
 public function get_status_filepath()
 {
     return Path::get_path() . '/.backup-' . $this->id . '-running';
 }
コード例 #12
0
ファイル: class-path.php プロジェクト: crazyyy/tarkettpolby
 /**
  * Clean any temporary / incomplete backups from the backups directory
  */
 public function cleanup()
 {
     // Don't cleanup a custom path, who knows what other stuff is there
     if (Path::get_path() === $this->get_custom_path()) {
         return;
     }
     foreach (new CleanUpIterator(new \DirectoryIterator($this->path)) as $file) {
         if ($file->isDot() || !$file->isReadable() || !$file->isFile()) {
             continue;
         }
         @unlink($file->getPathname());
     }
 }
コード例 #13
0
ファイル: actions.php プロジェクト: domalexxx/nashvancouver
/**
 * Cancels a running backup then redirect back to the backups page
 */
function request_cancel_backup()
{
    check_admin_referer('hmbkp_request_cancel_backup', 'hmbkp-request_cancel_backup_nonce');
    $schedule = new Scheduled_Backup(sanitize_text_field(urldecode($_GET['hmbkp_schedule_id'])));
    $status = $schedule->get_status();
    // Delete the running backup
    if ($status->get_backup_filename() && file_exists(trailingslashit(Path::get_path()) . $status->get_backup_filename())) {
        unlink(trailingslashit(Path::get_path()) . $status->get_backup_filename());
    }
    if (file_exists($status->get_status_filepath())) {
        unlink($status->get_status_filepath());
    }
    Path::get_instance()->cleanup();
    wp_safe_redirect(get_settings_url(), 303);
    die;
}
コード例 #14
0
ファイル: categories.view.php プロジェクト: marious/php-cms
    <?php 
if (isset(Path::get_path()['call_parts'][1])) {
    $catId = Path::get_path()['call_parts'][1];
    $cat = Category::read("SELECT * FROM categories WHERE id = ?", PDO::FETCH_CLASS, 'Category', [$catId]);
    if ($cat) {
        echo '<h2>' . $cat->name . '</h2>';
        echo '<p>' . $cat->content . '</p>';
    }
}
コード例 #15
0
ファイル: active.view.php プロジェクト: marious/php-cms
<?php

$activate_code = isset(Path::get_path()['call_parts'][1]) ? Path::get_path()['call_parts'][1] : null;
if ($activate_code) {
    $user = User::read("SELECT * FROM users WHERE activation = ?", PDO::FETCH_CLASS, 'User', [$activate_code]);
    if ($user) {
        $user->activation = '';
        $user->status = 1;
        $user->save();
        echo '<p class="success">Your account has been activated</p>';
    } else {
        echo '<p class="error">This activation link doesn\'t exist</p>';
    }
} else {
    header('Location: ' . HOST_NAME);
}
コード例 #16
0
				</th>

				<td>

					<code><?php 
    echo esc_html(str_ireplace(Path::get_root(), '', $exclude));
    ?>
</code>

				</td>

				<td>

					<?php 
    if (in_array($exclude, $excludes->get_default_excludes()) || Path::get_path() === trailingslashit(Path::get_root()) . 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 
コード例 #17
0
 /**
  * @return string
  */
 public static function test()
 {
     return substr(sprintf('%o', fileperms(Path::get_path())), -4);
 }
コード例 #18
0
ファイル: core.php プロジェクト: crazyyy/tarkettpolby
/**
 * Check if a backup is possible with regards to file
 * permissions etc.
 *
 * @return bool
 */
function is_backup_possible()
{
    if (!wp_is_writable(Path::get_path()) || !is_dir(Path::get_path())) {
        return false;
    }
    if (!is_readable(Path::get_root())) {
        return false;
    }
    return true;
}
コード例 #19
0
/**
 * Check whether the server is low on disk space.
 *
 * @return bool Whether there's less disk space less than 2 * the entire size of the site.
 */
function disk_space_low($backup_size = false)
{
    $disk_space = @disk_free_space(Path::get_path());
    if (!$disk_space) {
        return false;
    }
    if (!$backup_size) {
        $site_size = new Site_Size('complete', new Excludes());
        if (!$site_size->is_site_size_cached()) {
            return false;
        }
        $backup_size = $site_size->get_site_size() * 2;
    }
    return $backup_size >= $disk_space;
}
コード例 #20
0
 /**
  * Test that the backup path is correctly protected
  */
 public function testIsPathProtected()
 {
     // Fake that we're on Apache so we can also test .htaccess
     global $is_apache;
     $is_apache = true;
     // Test the default backup path
     $this->assertFileExists(Path::get_path() . '/index.html');
     $this->assertFileExists(Path::get_path() . '/.htaccess');
     // Test a custom backup path
     $this->path->set_path($this->custom_path);
     $this->path->calculate_path();
     $this->assertFileExists(Path::get_path() . '/index.html');
     $this->assertFileExists(Path::get_path() . '/.htaccess');
 }
コード例 #21
0
ファイル: categories.view.php プロジェクト: marious/php-cms
            if (isset($_POST['save'])) {
                $category->name = $_POST['name'];
                $category->title = $_POST['title'];
                $category->content = $_POST['content'];
                if ($category->save()) {
                    header('Location: ' . HOST_NAME . 'admin/' . $view . '/?message=success');
                } else {
                    header('Location: ' . HOST_NAME . 'admin/' . $view . '/?message=failed');
                }
            }
        } else {
            header('Location: ' . HOST_NAME . 'admin/404.php');
        }
    }
} elseif ($action != null && $action == 'delete') {
    $item = isset(Path::get_path()['call_parts'][2]) ? (int) Path::get_path()['call_parts'][2] : null;
    if ($item) {
        $category = Category::read("SELECT * FROM categories WHERE id = ?", PDO::FETCH_CLASS, 'Category', [$item]);
        if ($category != false) {
            if ($category->delete()) {
                header('Location: ' . HOST_NAME . 'admin/' . $view . '/?message=success');
            } else {
                header('Location: ' . HOST_NAME . 'admin/' . $view . '/?message=failed');
            }
        }
    } else {
        header('Location: ' . HOST_NAME . 'admin/404.php');
    }
}
?>
コード例 #22
0
/**
 * Check if a backup is possible with regards to file
 * permissions etc.
 *
 * @return bool
 */
function is_backup_possible()
{
    if (!wp_is_writable(Path::get_path()) || !is_dir(Path::get_path())) {
        return false;
    }
    if (!is_readable(Path::get_root())) {
        return false;
    }
    if (disk_space_low()) {
        return false;
    }
    if (!Requirement_Mysqldump_Command_Path::test() && !Requirement_PDO::test()) {
        return false;
    }
    if (!Requirement_Zip_Command_Path::test() && !Requirement_Zip_Archive::test()) {
        return false;
    }
    return true;
}
コード例 #23
0
 /**
  * Get the full filepath to the backup file.
  *
  * @return string The backup filepath.
  */
 public function get_backup_filepath()
 {
     return trailingslashit(Path::get_path()) . $this->get_backup_filename();
 }
コード例 #24
0
        break;
    case 'manually':
        $reoccurrence = __('manually', 'backupwordpress');
        break;
    default:
        $reoccurrence = __('manually', 'backupwordpress');
        $schedule->set_reoccurrence('manually');
}
$server = '<code title="' . __('Check the help tab to learn how to change where your backups are stored.', 'backupwordpress') . '">' . esc_attr(str_replace(Path::get_home_path(), '', Path::get_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'), Path::get_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 = array();
foreach (Services::get_services($schedule) as $file => $service) {
    if (is_wp_error($service)) {
        $email_msg = $service->get_error_message();
    } elseif ('Email' === $service->name) {
        $email_msg = wp_kses_post($service->display());
    } elseif ($service->is_service_active() && $service->display()) {
        $services[] = esc_html($service->display());
    }
}
コード例 #25
0
 /**
  * Get the backups created by this schedule
  *
  * @todo   look into using recursiveDirectoryIterator and recursiveRegexIterator
  * @return string[] - file paths of the backups
  */
 public function get_backups()
 {
     $files = array();
     if ($handle = @opendir(Path::get_path())) {
         while (false !== ($file = readdir($handle))) {
             if (pathinfo($file, PATHINFO_EXTENSION) === 'zip' && strpos($file, $this->get_id()) !== false && (isset($this->status) && $this->get_backup_filename() !== $file)) {
                 $files[@filemtime(trailingslashit(Path::get_path()) . $file)] = trailingslashit(Path::get_path()) . $file;
             }
         }
         closedir($handle);
     }
     krsort($files);
     return $files;
 }
コード例 #26
0
 public function testBackUpDirIsExcludedWhenBackUpDirIsInRoot()
 {
     $excludes = new Excludes();
     $this->assertContains(Path::get_root(), Path::get_path());
     $this->assertContains(str_replace(trailingslashit(Path::get_root()), '', Path::get_path()), $excludes->get_excludes());
 }