Example #1
0
 function process_dropbox_copy($destination_id, $file)
 {
     pb_backupbuddy::set_greedy_script_limits();
     require_once pb_backupbuddy::plugin_path() . '/lib/dropbuddy/dropbuddy.php';
     $dropbuddy = new pb_backupbuddy_dropbuddy(pb_backupbuddy::$options['remote_destinations'][$destination_id]['token']);
     if ($dropbuddy->authenticate() !== true) {
         if (!isset(pb_backupbuddy::$classes['core'])) {
             require_once pb_backupbuddy::plugin_path() . '/classes/core.php';
             pb_backupbuddy::$classes['core'] = new pb_backupbuddy_core();
         }
         pb_backupbuddy::$classes['core']->mail_error('Dropbox authentication failed in cron_process_dropbox_copy.');
         return false;
     }
     $destination_file = ABSPATH . 'wp-content/uploads/backupbuddy_backups/' . $file;
     if (file_exists($destination_file)) {
         $destination_file = str_replace('backup-', 'backup_copy_' . pb_backupbuddy::random_string(5) . '-', $destination_file);
     }
     pb_backupbuddy::status('error', 'About to get object (the file) from Dropbox cron.');
     file_put_contents($destination_file, $dropbuddy->get_file($file));
     pb_backupbuddy::status('error', 'Got object from Dropbox cron.');
 }
Example #2
0
        }
    }
    // Yes, I've Authorized BackupBuddy with Dropbox BUTTON.
    echo '<a href="';
    echo pb_backupbuddy::ajax_url('destination_picker') . '&add=dropbox&callback_data=' . pb_backupbuddy::_GET('callback_data') . '&t=' . time() . '&dropbox_auth=true';
    echo '" id="pb_dropbox_authorize" style="display: none;" class="button-primary">' . __("Yes, I've Authorized BackupBuddy with Dropbox", 'it-l10n-backupbuddy') . '</a>';
    //echo '<br>';
} else {
    // end add & edit mode.
    $hide_add = false;
}
// ACCOUNT INFO ONCE ACCEPTED.
if ($hide_add !== true) {
    if ($mode == 'edit' || $mode == 'add') {
        if (!isset($account_info)) {
            $dropbuddy = new pb_backupbuddy_dropbuddy(pb_backupbuddy::$options['remote_destinations'][$_GET['edit']]['token']);
            if ($dropbuddy->authenticate() === true) {
                $dropbox_connected = true;
                $account_info = $dropbuddy->get_account_info();
            } else {
                echo __('Dropbox Access Denied', 'it-l10n-backupbuddy');
            }
        }
        /*
        echo '<br>';
        echo '<a href="';
        echo pb_backupbuddy::ajax_url( 'destination_picker' ) . '&add=dropbox&callback_data=' . pb_backupbuddy::_GET( 'callback_data' ) . '&clear_dropboxtemptoken=true';
        echo '" class="button-secondary">', __('Re-authenticate Dropbox', 'it-l10n-backupbuddy' ), '</a>';
        */
        $settings_form->add_setting(array('type' => 'plaintext', 'name' => 'plaintext_owner', 'title' => __('Dropbox Owner', 'it-l10n-backupbuddy'), 'default' => $account_info['display_name'] . ' (UID: ' . $account_info['uid'] . ') [<a href="' . $account_info['referral_link'] . '" target="_new">' . __('Referral Link', 'it-l10n-backupbuddy') . '</a>]'));
        $settings_form->add_setting(array('type' => 'plaintext', 'name' => 'plaintext_email', 'title' => __('Email', 'it-l10n-backupbuddy'), 'default' => $account_info['email']));
Example #3
0
 function remote_send_dropbox($token, $directory, $file, $limit = 0, $send_importbuddy = false)
 {
     // Normalize picky dropbox directory.
     $directory = trim($directory, '\\/');
     $directory = str_replace(' ', '%20', $directory);
     pb_backupbuddy::status('details', 'Starting Dropbox transfer.');
     require_once pb_backupbuddy::plugin_path() . '/lib/dropbuddy/dropbuddy.php';
     $dropbuddy = new pb_backupbuddy_dropbuddy($token);
     if ($dropbuddy->authenticate() !== true) {
         pb_backupbuddy::status('details', 'Dropbox authentication failed in remote_send_dropbox.');
         return false;
     }
     pb_backupbuddy::status('details', 'About to put object `' . basename($file) . '` to Dropbox cron.');
     $status = $dropbuddy->put_file($directory . '/' . basename($file), $file);
     if ($status === true) {
         pb_backupbuddy::status('details', 'SUCCESS sending to Dropbox!');
     } else {
         pb_backupbuddy::status('details', 'Dropbox file send FAILURE. HTTP Status: ' . $status['httpStatus'] . '; Body: ' . $status['body'], 'error');
         return false;
     }
     // Handle sending importbuddy.php.
     if ($send_importbuddy === true) {
         pb_backupbuddy::status('details', 'Sending importbuddy to Dropbox based on settings.');
         $importbuddy_temp = pb_backupbuddy::$options['temp_directory'] . 'importbuddy_' . pb_backupbuddy::random_string(10) . '.php.tmp';
         // Full path & filename to temporary importbuddy
         $this->importbuddy($importbuddy_temp);
         // Create temporary importbuddy.
         $dropbuddy->put_file($directory . '/' . basename($file), $file);
         @unlink($importbuddy_temp);
         // Delete temporary importbuddy.
     }
     // Start remote backup limit
     if ($limit > 0) {
         pb_backupbuddy::status('details', 'Dropbox file limit in place. Proceeding with enforcement.');
         $meta_data = $dropbuddy->get_meta_data($directory);
         // Create array of backups and organize by date
         $bkupprefix = $this->backup_prefix();
         $backups = array();
         foreach ((array) $meta_data['contents'] as $file) {
             // check if file is backup
             if (strpos($file['path'], 'backup-' . $bkupprefix . '-') !== FALSE) {
                 $backups[$file['path']] = strtotime($file['modified']);
             }
         }
         arsort($backups);
         if (count($backups) > $limit) {
             pb_backupbuddy::status('details', 'Dropbox backup file count of `' . count($backups) . '` exceeds limit of `' . $limit . '`.');
             $i = 0;
             $delete_fail_count = 0;
             foreach ($backups as $buname => $butime) {
                 $i++;
                 if ($i > $limit) {
                     if (!$dropbuddy->delete($buname)) {
                         // Try to delete backup on Dropbox. Increment failure count if unable to.
                         pb_backupbuddy::status('details', 'Unable to delete excess Dropbox file: `' . $buname . '`');
                         $delete_fail_count++;
                     }
                 }
             }
             if ($delete_fail_count !== 0) {
                 $this->mail_error(sprintf(__('Dropbox remote limit could not delete %s backups.', 'it-l10n-backupbuddy'), $delete_fail_count));
             }
         }
     } else {
         pb_backupbuddy::status('details', 'No Dropbox file limit to enforce.');
     }
     // End remote backup limit
     return true;
     // Success if made it this far.
 }
Example #4
0
 function process_dropbox_copy($destination_id, $file)
 {
     pb_backupbuddy::set_greedy_script_limits();
     if (!class_exists('backupbuddy_core')) {
         require_once pb_backupbuddy::plugin_path() . '/classes/core.php';
     }
     require_once pb_backupbuddy::plugin_path() . '/destinations/dropbox/lib/dropbuddy/dropbuddy.php';
     $dropbuddy = new pb_backupbuddy_dropbuddy(pb_backupbuddy::$options['remote_destinations'][$destination_id]['token']);
     if ($dropbuddy->authenticate() !== true) {
         if (!class_exists('backupbuddy_core')) {
             require_once pb_backupbuddy::plugin_path() . '/classes/core.php';
         }
         backupbuddy_core::mail_error('Dropbox authentication failed in cron_process_dropbox_copy.');
         return false;
     }
     $destination_file = backupbuddy_core::getBackupDirectory() . basename($file);
     if (file_exists($destination_file)) {
         $destination_file = str_replace('backup-', 'backup_copy_' . pb_backupbuddy::random_string(5) . '-', $destination_file);
     }
     pb_backupbuddy::status('error', 'About to get file `' . $file . '` from Dropbox and save to `' . $destination_file . '`.');
     file_put_contents($destination_file, $dropbuddy->get_file($file));
     pb_backupbuddy::status('error', 'Got object from Dropbox cron.');
 }
Example #5
0
 public static function send($settings = array(), $files = array())
 {
     $token =& $settings['token'];
     $directory = $settings['directory'];
     $limit = $settings['archive_limit'];
     // Normalize picky dropbox directory.
     $directory = trim($directory, '\\/');
     pb_backupbuddy::status('details', 'About to load Dropbuddy library...');
     require_once pb_backupbuddy::plugin_path() . '/destinations/dropbox/lib/dropbuddy/dropbuddy.php';
     pb_backupbuddy::status('details', 'Dropbuddy loaded.');
     //pb_backupbuddy::status( 'details', 'Authenticating to dropbox with token: `' . implode( ';', $token ) . '`.' );
     $dropbuddy = new pb_backupbuddy_dropbuddy($token);
     pb_backupbuddy::status('details', 'Dropbuddy object created.');
     if ($dropbuddy->authenticate() !== true) {
         pb_backupbuddy::status('details', 'Dropbox authentication failed in send().');
         return false;
     } else {
         pb_backupbuddy::status('details', 'Authenticated to Dropbox.');
     }
     pb_backupbuddy::status('details', 'Looping through files to send to Dropbox.');
     foreach ($files as $file) {
         pb_backupbuddy::status('details', 'About to put object `' . basename($file) . '` to Dropbox cron.');
         try {
             $status = $dropbuddy->put_file($directory . '/' . basename($file), $file);
         } catch (Dropbox_Exception $e) {
             pb_backupbuddy::status('error', 'Dropbox exception caught. Error #8954785: ' . $e->getMessage());
             return false;
         }
         if ($status === true) {
             pb_backupbuddy::status('details', 'SUCCESS sending to Dropbox!');
         } else {
             pb_backupbuddy::status('details', 'Dropbox file send FAILURE. HTTP Status: ' . $status['httpStatus'] . '; Body: ' . $status['body'], 'error');
             return false;
         }
         // Start remote backup limit
         if ($limit > 0) {
             pb_backupbuddy::status('details', 'Dropbox file limit in place. Proceeding with enforcement.');
             $meta_data = $dropbuddy->get_meta_data($directory);
             // Create array of backups and organize by date
             $bkupprefix = pb_backupbuddy::$classes['core']->backup_prefix();
             $backups = array();
             foreach ((array) $meta_data['contents'] as $looping_file) {
                 // check if file is backup
                 if (strpos($looping_file['path'], 'backup-' . $bkupprefix . '-') !== false) {
                     $backups[$looping_file['path']] = strtotime($looping_file['modified']);
                 }
             }
             arsort($backups);
             if (count($backups) > $limit) {
                 pb_backupbuddy::status('details', 'Dropbox backup file count of `' . count($backups) . '` exceeds limit of `' . $limit . '`.');
                 $i = 0;
                 $delete_fail_count = 0;
                 foreach ($backups as $buname => $butime) {
                     $i++;
                     if ($i > $limit) {
                         if (!$dropbuddy->delete($buname)) {
                             // Try to delete backup on Dropbox. Increment failure count if unable to.
                             pb_backupbuddy::status('details', 'Unable to delete excess Dropbox file: `' . $buname . '`');
                             $delete_fail_count++;
                         }
                     }
                 }
                 if ($delete_fail_count !== 0) {
                     pb_backupbuddy::$classes['core']->mail_error(sprintf(__('Dropbox remote limit could not delete %s backups.', 'it-l10n-backupbuddy'), $delete_fail_count));
                 }
             }
         } else {
             pb_backupbuddy::status('details', 'No Dropbox file limit to enforce.');
         }
         // End remote backup limit
     }
     // end foreach.
     pb_backupbuddy::status('details', 'All files sent.');
     return true;
     // Success if made it this far.
 }
Example #6
0
<?php

pb_backupbuddy::$ui->title('Dropbox');
require_once pb_backupbuddy::plugin_path() . '/destinations/dropbox/lib/dropbuddy/dropbuddy.php';
$dropbuddy = new pb_backupbuddy_dropbuddy($destination['token']);
if ($dropbuddy->authenticate() === true) {
    $account_info = $dropbuddy->get_account_info();
} else {
    $account_info = false;
}
if (!isset($destination['directory'])) {
    $destination['directory'] = '';
}
if (!isset($destination['title'])) {
    $destination['title'] = '';
}
$meta_data = $dropbuddy->get_meta_data($destination['directory']);
/*
echo '<pre>';
print_r( $meta_data ) );
echo '</pre>';
*/
// Delete dropbox backups
if (!empty($_POST['delete_file'])) {
    pb_backupbuddy::verify_nonce();
    $delete_count = 0;
    if (!empty($_POST['files']) && is_array($_POST['files'])) {
        // loop through and delete dropbox files
        foreach ($_POST['files'] as $dropboxfile) {
            $delete_count++;
            // Delete dropbox file
Example #7
0
 public static function send($settings = array(), $files = array(), $send_id = '')
 {
     global $pb_backupbuddy_destination_errors;
     if ('1' == $settings['disabled']) {
         $pb_backupbuddy_destination_errors[] = __('Error #48933: This destination is currently disabled. Enable it under this destination\'s Advanced Settings.', 'it-l10n-backupbuddy');
         return false;
     }
     if (!is_array($files)) {
         $files = array($files);
     }
     $token =& $settings['token'];
     $directory = '/' . ltrim($settings['directory'], '/\\');
     $limit = $settings['archive_limit'];
     // Normalize picky dropbox directory.
     $directory = trim($directory, '\\/');
     pb_backupbuddy::status('details', 'About to load Dropbuddy library...');
     require_once pb_backupbuddy::plugin_path() . '/destinations/dropbox/lib/dropbuddy/dropbuddy.php';
     pb_backupbuddy::status('details', 'Dropbuddy loaded.');
     //pb_backupbuddy::status( 'details', 'Authenticating to dropbox with token: `' . implode( ';', $token ) . '`.' );
     $dropbuddy = new pb_backupbuddy_dropbuddy($token);
     pb_backupbuddy::status('details', 'Dropbuddy object created.');
     if ($dropbuddy->authenticate() !== true) {
         pb_backupbuddy::status('details', 'Dropbox authentication failed in send().');
         return false;
     } else {
         pb_backupbuddy::status('details', 'Authenticated to Dropbox.');
     }
     $memory = pb_backupbuddy_destination_dropbox::memory_guesstimate();
     pb_backupbuddy::status('details', 'Dropbox limitation estimated to be max transfer size of ' . round($memory['hypothesis'], 0) . 'MB based on PHP memory limit of ' . $memory['limit'] . 'MB & current loaded WordPress plugins.');
     pb_backupbuddy::status('details', 'Looping through files to send to Dropbox.');
     foreach ($files as $file) {
         pb_backupbuddy::status('details', 'About to put file `' . basename($file) . '` (' . pb_backupbuddy::$format->file_size(filesize($file)) . ') to Dropbox (v1).');
         try {
             $status = $dropbuddy->put_file($directory . '/' . basename($file), $file);
         } catch (Dropbox_Exception $e) {
             pb_backupbuddy::status('error', 'Dropbox exception caught. Error #8954785: ' . $e->getMessage());
             return false;
         }
         if ($status === true) {
             pb_backupbuddy::status('details', 'SUCCESS sending to Dropbox!');
         } else {
             pb_backupbuddy::status('details', 'Dropbox file send FAILURE. HTTP Status: ' . $status['httpStatus'] . '; Body: ' . $status['body'], 'error');
             return false;
         }
         // Start remote backup limit
         if ($limit > 0) {
             pb_backupbuddy::status('details', 'Dropbox file limit in place. Proceeding with enforcement.');
             $meta_data = $dropbuddy->get_meta_data($directory);
             // Create array of backups and organize by date
             $bkupprefix = backupbuddy_core::backup_prefix();
             $backups = array();
             foreach ((array) $meta_data['contents'] as $looping_file) {
                 if ('1' == $looping_file['is_dir']) {
                     // Additional safety layer to ignore subdirectory.
                     continue;
                 }
                 // check if file is backup
                 if (strpos($looping_file['path'], 'backup-' . $bkupprefix . '-') !== false) {
                     $backups[$looping_file['path']] = strtotime($looping_file['modified']);
                 }
             }
             arsort($backups);
             if (count($backups) > $limit) {
                 pb_backupbuddy::status('details', 'Dropbox backup file count of `' . count($backups) . '` exceeds limit of `' . $limit . '`.');
                 $i = 0;
                 $delete_fail_count = 0;
                 foreach ($backups as $buname => $butime) {
                     $i++;
                     if ($i > $limit) {
                         if (!$dropbuddy->delete($buname)) {
                             // Try to delete backup on Dropbox. Increment failure count if unable to.
                             pb_backupbuddy::status('details', 'Unable to delete excess Dropbox file: `' . $buname . '`');
                             $delete_fail_count++;
                         }
                     }
                 }
                 if ($delete_fail_count !== 0) {
                     backupbuddy_core::mail_error(sprintf(__('Dropbox remote limit could not delete %s backups.', 'it-l10n-backupbuddy'), $delete_fail_count));
                 }
             }
         } else {
             pb_backupbuddy::status('details', 'No Dropbox file limit to enforce.');
         }
         // End remote backup limit
     }
     // end foreach.
     pb_backupbuddy::status('details', 'All files sent.');
     return true;
     // Success if made it this far.
 }