public function out($source, $file, $processed_file = null) { if ($this->error_count > self::MAX_ERRORS) { throw new Exception(sprintf(__('The backup is having trouble uploading files to Dropbox, it has failed %s times and is aborting the backup.', 'wpbtd'), self::MAX_ERRORS)); } if (!$this->dropbox) { throw new Exception(__("Dropbox API not set")); } $dropbox_path = $this->config->get_dropbox_path($source, $file, $this->root); try { $directory_contents = $this->dropbox->get_directory_contents($dropbox_path); if (!in_array(basename($file), $directory_contents) || filemtime($file) > $this->config->get_option('last_backup_time')) { $file_size = filesize($file); if ($file_size > $this->get_chunked_upload_threashold()) { $msg = __("Uploading large file '%s' (%sMB) in chunks", 'wpbtd'); if ($processed_file && $processed_file->offset > 0) { $msg = __("Resuming upload of large file '%s'", 'wpbtd'); } WPB2D_Factory::get('logger')->log(sprintf($msg, basename($file), round($file_size / 1048576, 1))); return $this->dropbox->chunk_upload_file($dropbox_path, $file, $processed_file); } else { return $this->dropbox->upload_file($dropbox_path, $file); } } } catch (Exception $e) { WPB2D_Factory::get('logger')->log(sprintf(__("Error uploading '%s' to Dropbox: %s", 'wpbtd'), $file, strip_tags($e->getMessage()))); $this->error_count++; } }
public function init() { $this->config = WPB2D_Factory::get('config'); if (!extension_loaded('curl')) { throw new Exception(sprintf(__('The cURL extension is not loaded. %sPlease ensure its installed and activated.%s', 'wpbtd'), '<a href="http://php.net/manual/en/curl.installation.php">', '</a>')); } $this->oauth = new Dropbox_OAuth_Consumer_Curl(self::CONSUMER_KEY, self::CONSUMER_SECRET); $this->oauth_state = $this->config->get_option('oauth_state'); $this->request_token = $this->get_token('request'); $this->access_token = $this->get_token('access'); if ($this->oauth_state == 'request') { //If we have not got an access token then we need to grab one try { $this->oauth->setToken($this->request_token); $this->access_token = $this->oauth->getAccessToken(); $this->oauth_state = 'access'; $this->oauth->setToken($this->access_token); $this->save_tokens(); //Supress the error because unlink, then init should be called } catch (Exception $e) { } } elseif ($this->oauth_state == 'access') { $this->oauth->setToken($this->access_token); } else { //If we don't have an acess token then lets setup a new request $this->request_token = $this->oauth->getRequestToken(); $this->oauth->setToken($this->request_token); $this->oauth_state = 'request'; $this->save_tokens(); } $this->dropbox = new Dropbox_API($this->oauth); $this->dropbox->setTracker(new WPB2D_UploadTracker()); }
public function track_upload($file, $upload_id, $offset) { $offset = is_null($offset) ? 0 : $offset; WPB2D_Factory::get('config')->die_if_stopped(); $this->processed_files->update_file($file, $upload_id, $offset); WPB2D_Factory::get('logger')->log(sprintf(__("Uploaded %sMB of %sMB", 'wpbtd'), round($offset / 1048576, 1), round(filesize($file) / 1048576, 1))); }
public function __construct() { $this->db = WPB2D_Factory::db(); $ret = $this->db->get_results("SELECT * FROM {$this->db->prefix}wpb2d_processed_{$this->getTableName()}"); if (is_array($ret)) { $this->processed = $ret; } }
public function __construct() { $this->db = WPB2D_Factory::db(); $result = $this->db->get_results("SELECT * FROM {$this->db->prefix}wpb2d_excluded_files WHERE isdir = 0"); foreach ($result as $value) { $this->excluded_files[] = $value->file; } $result = $this->db->get_results("SELECT * FROM {$this->db->prefix}wpb2d_excluded_files WHERE isdir = 1"); foreach ($result as $value) { $this->excluded_dirs[] = $value->file; } }
public function get_log_file() { if (!$this->logFile) { WPB2D_BackupController::create_dump_dir(); $path = WPB2D_Factory::get('config')->get_backup_dir() . DIRECTORY_SEPARATOR . self::LOGFILE; $files = glob($path . '.*'); if (isset($files[0])) { $this->logFile = $files[0]; } else { $this->logFile = $path . '.' . WPB2D_Factory::secret(self::LOGFILE); } } return $this->logFile; }
* but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA. */ try { if ($errors = get_option('wpb2d-init-errors')) { delete_option('wpb2d-init-errors'); throw new Exception(__('WordPress Backup to Dropbox failed to initialize due to these database errors.', 'wpbtd') . '<br /><br />' . $errors); } $validation_errors = null; $dropbox = WPB2D_Factory::get('dropbox'); $config = WPB2D_Factory::get('config'); $backup = new WPB2D_BackupController(); $backup->create_dump_dir(); $disable_backup_now = $config->get_option('in_progress'); //We have a form submit so update the schedule and options if (array_key_exists('wpb2d_save_changes', $_POST)) { check_admin_referer('backup_to_dropbox_options_save'); if (preg_match('/[^A-Za-z0-9-_.\\/]/', $_POST['dropbox_location'])) { add_settings_error('wpb2d_options', 'invalid_subfolder', __('The sub directory must only contain alphanumeric characters.', 'wpbtd'), 'error'); $dropbox_location = $_POST['dropbox_location']; $store_in_subfolder = true; } else { $config->set_schedule($_POST['day'], $_POST['time'], $_POST['frequency'])->set_option('store_in_subfolder', $_POST['store_in_subfolder'] == "on")->set_option('dropbox_location', $_POST['dropbox_location']); add_settings_error('general', 'settings_updated', __('Settings saved.'), 'updated'); } } elseif (array_key_exists('unlink', $_POST)) {
function wpb2d_init() { try { if (WPB2D_Factory::get('config')->get_option('database_version') < BACKUP_TO_DROPBOX_DATABASE_VERSION) { wpb2d_install(); } if (!get_option('wpb2d-premium-extensions')) { add_option('wpb2d-premium-extensions', array(), false, 'no'); } } catch (Exception $e) { error_log($e->getMessage()); } }
* (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA. */ $config = WPB2D_Factory::get('config'); if (!$config->get_option('in_progress')) { spawn_cron(); } $log = WPB2D_Factory::get('logger')->get_log(); if (empty($log)) { ?> <p><?php _e('You have not run a backup yet. When you do you will see a log of it here.'); ?> </p> <?php } else { ?> <ul> <?php foreach (array_reverse($log) as $log_item) { ?> <li> <?php
* @license This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA. */ WPB2D_Factory::get('config')->set_time_limit(); WPB2D_Factory::get('config')->set_memory_limit(); try { $file_list = new WPB2D_FileList(); if (isset($_POST['dir'])) { //Convert to the os' directiry separator $_POST['dir'] = str_replace('/', DIRECTORY_SEPARATOR, urldecode($_POST['dir'])); if (file_exists($_POST['dir']) && is_readable($_POST['dir'])) { $files = scandir($_POST['dir']); natcasesort($files); if (count($files) > 2) { /* The 2 accounts for . and .. */ echo "<ul class=\"jqueryFileTree\" style=\"display: none;\">"; // All dirs foreach ($files as $file) { if ($file != '.' && $file != '..' && file_exists($_POST['dir'] . $file) && is_dir($_POST['dir'] . $file)) { if (!is_readable($_POST['dir']) || $_POST['dir'] == dirname(get_sanitized_home_path()) && !strstr($file, basename(get_sanitized_home_path()))) {
public function __construct() { $this->dropbox = WPB2D_Factory::get('dropbox'); $this->config = WPB2D_Factory::get('config'); }
public static function create_dump_dir() { $dump_dir = WPB2D_Factory::get('config')->get_backup_dir(); $error_message = sprintf(__("WordPress Backup to Dropbox requires write access to '%s', please ensure it exists and has write permissions.", 'wpbtd'), $dump_dir); if (!file_exists($dump_dir)) { //It really pains me to use the error suppressor here but PHP error handling sucks :-( if (!@mkdir($dump_dir)) { throw new Exception($error_message); } } elseif (!is_writable($dump_dir)) { throw new Exception($error_message); } self::create_silence_file(); }
public function die_if_stopped() { $in_progress = $this->db->get_var("SELECT value FROM {$this->db->prefix}wpb2d_options WHERE name = 'in_progress'"); if (!$in_progress) { $msg = __('Backup stopped by user.', 'wpbtd'); WPB2D_Factory::get('logger')->log($msg); die($msg); } }
public static function reset() { self::$objectCache = array(); }
* @author Michael De Wildt (http://www.mikeyd.com.au/) * @license This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA. */ $manager = WPB2D_Factory::get('extension-manager'); if (isset($_REQUEST['error'])) { add_settings_error('error', 'wpb2d_premium_error', sprintf(__('There was an error with your payment, please contact %s to resolve.', 'wpbtd'), '<a href="mailto:michael.dewildt@gmail.com">Mikey</a>'), 'error'); } if (isset($_REQUEST['title'])) { add_settings_error('general', 'wpb2d_premium_success', sprintf(__('You have succesfully purchased %s.', 'wpbtd'), '<strong>' . esc_attr($_REQUEST['title']) . '</strong>'), 'updated'); } if (isset($_POST['name'])) { try { $ext = $manager->install($_POST['name']); $slug = $manager->get_menu_slug($ext); $title = $ext->get_menu(); add_settings_error('general', 'wpb2d_premium_success', __('Installation successful. Please configure the extension from its menu item.', 'wpbtd'), 'updated'); ?> <script type='text/javascript'> jQuery(document).ready(function ($) {
private function write_db_dump_header() { $dump_location = $this->config->get_backup_dir(); if (!is_writable($dump_location)) { $msg = sprintf(__("A database backup cannot be created because WordPress does not have write access to '%s', please ensure this directory has write access.", 'wpbtd'), $dump_location); WPB2D_Factory::get('logger')->log($msg); return false; } $blog_time = strtotime(current_time('mysql')); $this->write_to_temp("-- WordPress Backup to Dropbox SQL Dump\n"); $this->write_to_temp("-- Version " . BACKUP_TO_DROPBOX_VERSION . "\n"); $this->write_to_temp("-- http://wpb2d.com\n"); $this->write_to_temp("-- Generation Time: " . date("F j, Y", $blog_time) . " at " . date("H:i", $blog_time) . "\n\n"); $this->write_to_temp('SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";' . "\n\n"); //I got this out of the phpMyAdmin database dump to make sure charset is correct $this->write_to_temp("/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;\n"); $this->write_to_temp("/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;\n"); $this->write_to_temp("/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;\n"); $this->write_to_temp("/*!40101 SET NAMES utf8 */;\n\n"); $this->write_to_temp("--\n-- Create and use the backed up database\n--\n\n"); $this->write_to_temp("CREATE DATABASE IF NOT EXISTS " . DB_NAME . ";\n"); $this->write_to_temp("USE " . DB_NAME . ";\n\n"); $this->persist(); $this->processed->update_table('header', -1); }