本文整理汇总了PHP中pb_backupbuddy::random_string方法的典型用法代码示例。如果您正苦于以下问题:PHP pb_backupbuddy::random_string方法的具体用法?PHP pb_backupbuddy::random_string怎么用?PHP pb_backupbuddy::random_string使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pb_backupbuddy
的用法示例。
在下文中一共展示了pb_backupbuddy::random_string方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: test
public static function test($settings)
{
$email = $settings['address'];
pb_backupbuddy::status('details', 'Testing email destination. Sending ImportBuddy.php.');
$importbuddy_temp = backupbuddy_core::getTempDirectory() . 'importbuddy_' . pb_backupbuddy::random_string(10) . '.php.tmp';
// Full path & filename to temporary importbuddy
backupbuddy_core::importbuddy($importbuddy_temp);
// Create temporary importbuddy.
$files = array($importbuddy_temp);
if (pb_backupbuddy::$options['email_return'] != '') {
$email_return = pb_backupbuddy::$options['email_return'];
} else {
$email_return = get_option('admin_email');
}
$headers = 'From: BackupBuddy <' . $email_return . '>' . "\r\n";
$wp_mail_result = wp_mail($email, 'BackupBuddy Test', 'BackupBuddy destination test for ' . site_url(), $headers, $files);
pb_backupbuddy::status('details', 'Sent test email.');
@unlink($importbuddy_temp);
if ($wp_mail_result === true) {
// WP sent. Hopefully it makes it!
return true;
} else {
// WP couldn't try to send.
echo 'WordPress was unable to attempt to send email. Check your WordPress & server settings.';
return false;
}
}
示例2: run
public function run($arguments)
{
$arguments = Ithemes_Sync_Functions::merge_defaults($arguments, $this->default_arguments);
$profile = $arguments['profile'];
if ('db' == $profile) {
// db profile is always index 1.
$profile = '1';
} elseif ('full' == $profile) {
// full profile is always index 2.
$profile = '2';
}
if (is_numeric($profile)) {
if (isset(pb_backupbuddy::$options['profiles'][$profile])) {
$profileArray = pb_backupbuddy::$options['profiles'][$profile];
} else {
return array('api' => '0', 'status' => 'error', 'message' => 'Error #2332904: Invalid profile ID `' . htmlentities($profile) . '`. Profile with this number was not found. Try deactivating then reactivating the plugin. If this fails please reset the plugin Settings back to Defaults from the Settings page.');
}
} else {
return array('api' => '0', 'status' => 'error', 'message' => 'Error #85489548955. Invalid profile ID not numeric: `' . htmlentities($profile) . '`.');
}
require_once pb_backupbuddy::plugin_path() . '/classes/backup.php';
pb_backupbuddy::$classes['backup'] = new pb_backupbuddy_backup();
// Set serial ahead of time so can be used by AJAX before backup procedure actually begins.
$serial = pb_backupbuddy::random_string(10);
$profileArray['backup_mode'] = '2';
// Force modern mode when running under sync.
// Run the backup!
if (pb_backupbuddy::$classes['backup']->start_backup_process($profileArray, 'manual', array(), array(), 'it-sync', $serial, array()) !== true) {
return array('api' => '0', 'status' => 'error', 'message' => 'Error #435832: Backup failed. See BackupBuddy log for details.');
}
return array('api' => '0', 'status' => 'ok', 'message' => 'Backup initiated successfully.');
}
示例3: test
public static function test($settings)
{
/*
if ( ( $settings['address'] == '' ) || ( $settings['username'] == '' ) || ( $settings['password'] == '' ) ) {
return __('Missing required input.', 'it-l10n-backupbuddy' );
}
*/
// Try sending a file.
return pb_backupbuddy_destinations::send($settings, dirname(dirname(__FILE__)) . '/remote-send-test.php', $send_id = 'TEST-' . pb_backupbuddy::random_string(12));
// 3rd param true forces clearing of any current uploads.
}
示例4: backup
/**
* Run a BackupBuddy backup. http://getbackupbuddy.com
*
* ## OPTIONS
*
* <profile>
* : Profile may either specify the profile ID number, "full" to run the first defined Full backup profile, or "db" to run the first defined Database-only backup profile. The first Full and Database-only profiles are always available as they are not user-deletable. To find the profile number, run a backup inside BackupBuddy in WordPress and note the number at the end of the URL (3 in this case): http://...&backupbuddy_backup=3
*
* [--quiet]
* : Suppresses display of status log information from being output to the screen.
*
* ## EXAMPLES
*
* RUN FULL BACKUP: wp backupbuddy backup full
* RUN PROFILE #3: wp backupbuddy backup 3
*
* @synopsis <profile> [--quiet]
*/
public function backup($args, $assoc_args)
{
$profile = $args[0];
if ('db' == $profile) {
// db profile is always index 1.
$profile = '1';
} elseif ('full' == $profile) {
// full profile is always index 2.
$profile = '2';
}
if (is_numeric($profile)) {
if (isset(pb_backupbuddy::$options['profiles'][$profile])) {
$profileArray = pb_backupbuddy::$options['profiles'][$profile];
} else {
WP_CLI::error('Error #2332904: Invalid profile ID `' . htmlentities($profile) . '`. Profile with this number was not found. Try deactivating then reactivating the plugin. If this fails please reset the plugin Settings back to Defaults from the Settings page.');
return;
}
} else {
WP_CLI::error('Error #85489548955. Invalid profile ID not numeric: `' . htmlentities($profile) . '`.');
return;
}
require_once pb_backupbuddy::plugin_path() . '/classes/backup.php';
pb_backupbuddy::$classes['backup'] = new pb_backupbuddy_backup();
// Set serial ahead of time so can be used by AJAX before backup procedure actually begins.
$serial = pb_backupbuddy::random_string(10);
$profileArray['backup_mode'] = '1';
// Force classic mode when running under command line.
if (!isset($assoc_args['quiet'])) {
define('BACKUPBUDDY_WP_CLI', true);
}
// Run the backup!
if (pb_backupbuddy::$classes['backup']->start_backup_process($profileArray, 'manual', array(), array(), 'wp-cli', $serial, array()) !== true) {
WP_CLI::error('Error #435832: Backup failed. See BackupBuddy log for details.');
return;
}
WP_CLI::success('Backup completed successfully.');
return;
}
示例5: start_backup_process
function start_backup_process($profile, $trigger = 'manual', $pre_backup = array(), $post_backup = array(), $schedule_title = '', $serial_override = '', $export_plugins = array())
{
// Load profile defaults.
$profile = array_merge(pb_backupbuddy::settings('profile_defaults'), $profile);
foreach ($profile as $profile_item_name => &$profile_item) {
// replace non-overridden defaults with actual default value.
if ('-1' == $profile_item) {
// Set to use default so go grab default.
if (isset(pb_backupbuddy::$options['profiles'][0][$profile_item_name])) {
$profile_item = pb_backupbuddy::$options['profiles'][0][$profile_item_name];
// Grab value from defaults profile and replace with it.
}
}
}
// Handle backup mode.
$backup_mode = pb_backupbuddy::$options['backup_mode'];
// Load global default mode.
if ('1' == $profile['backup_mode']) {
// Profile forces classic.
$backup_mode = '1';
} elseif ('2' == $profile['backup_mode']) {
// Profiles forces modern.
$backup_mode = '2';
}
$profile['backup_mode'] = $backup_mode;
unset($backup_mode);
// If classic mode then we need to redirect output to displaying inline via JS instead of AJAX-based.
if ('1' == $profile['backup_mode']) {
//global $pb_backupbuddy_js_status;
//$pb_backupbuddy_js_status = true;
}
if ($serial_override != '') {
$serial = $serial_override;
} else {
$serial = pb_backupbuddy::random_string(10);
}
pb_backupbuddy::set_status_serial($serial);
// Default logging serial.
global $wp_version;
pb_backupbuddy::status('details', 'BackupBuddy v' . pb_backupbuddy::settings('version') . ' using WordPress v' . $wp_version . ' on ' . PHP_OS . '.');
//pb_backupbuddy::status( 'details', __('Peak memory usage', 'it-l10n-backupbuddy' ) . ': ' . round( memory_get_peak_usage() / 1048576, 3 ) . ' MB' );
if ($this->pre_backup($serial, $profile, $trigger, $pre_backup, $post_backup, $schedule_title, $export_plugins) === false) {
pb_backupbuddy::status('details', 'pre_backup() function failed.');
return false;
}
if ($trigger == 'scheduled' && pb_backupbuddy::$options['email_notify_scheduled_start'] != '') {
pb_backupbuddy::status('details', __('Sending scheduled backup start email notification if applicable.', 'it-l10n-backupbuddy'));
backupbuddy_core::mail_notify_scheduled($serial, 'start', __('Scheduled backup', 'it-l10n-backupbuddy') . ' (' . $this->_backup['schedule_title'] . ') has begun.');
}
if ($profile['backup_mode'] == '2') {
// Modern mode with crons.
pb_backupbuddy::status('message', 'Running in modern backup mode based on settings. Mode value: `' . $profile['backup_mode'] . '`. Trigger: `' . $trigger . '`.');
unset($this->_backup_options);
// File unlocking is handled on deconstruction. Make sure unlocked before firing off another cron spawn.
// If using alternate cron on a manually triggered backup then skip running the cron on this pageload to avoid header already sent warnings.
if ($trigger != 'manual' || defined('ALTERNATE_WP_CRON') && ALTERNATE_WP_CRON) {
$this->cron_next_step(false);
} else {
//$this->cron_next_step( true );
$this->cron_next_step(false);
// as of Aug 9, 2013 no longer spawn the cron. Caused very odd issue of double code runs.
}
} else {
// Classic mode; everything runs in this single PHP page load.
pb_backupbuddy::status('message', 'Running in classic backup mode based on settings.');
$this->process_backup($this->_backup['serial'], $trigger);
}
return true;
}
示例6: remote_test
function remote_test()
{
if (defined('PB_DEMO_MODE')) {
die('Access denied in demo mode.');
}
if (!isset(pb_backupbuddy::$classes['core'])) {
require_once pb_backupbuddy::plugin_path() . '/classes/core.php';
pb_backupbuddy::$classes['core'] = new pb_backupbuddy_core();
}
if ($_POST['#type'] == 's3') {
if ($_POST['#ssl'] == '1') {
$s3_ssl = true;
} else {
$s3_ssl = false;
}
if (true === ($response = pb_backupbuddy::$classes['core']->test_s3($_POST['#accesskey'], $_POST['#secretkey'], $_POST['#bucket'], $_POST['#directory'], $s3_ssl))) {
echo __('Test completed successfully.', 'it-l10n-backupbuddy');
} else {
echo __('Failure', 'it-l10n-backupbuddy') . '; ' . $response;
}
} elseif ($_POST['#type'] == 'rackspace') {
if (true === ($response = pb_backupbuddy::$classes['core']->test_rackspace($_POST['#username'], $_POST['#api_key'], $_POST['#container'], $_POST['#server']))) {
echo __('Test completed successfully.', 'it-l10n-backupbuddy');
} else {
echo __('Failure', 'it-l10n-backupbuddy') . '; ' . $response;
}
} elseif ($_POST['#type'] == 'ftp') {
if ($_POST['#ftps'] == '0') {
$ftp_type = 'ftp';
} else {
$ftp_type = 'ftps';
}
if (true === ($response = pb_backupbuddy::$classes['core']->test_ftp($_POST['#address'], $_POST['#username'], $_POST['#password'], $_POST['#path'], $ftp_type))) {
echo __('Test completed successfully.', 'it-l10n-backupbuddy');
} else {
echo __('Failure', 'it-l10n-backupbuddy') . '; ' . $response;
}
} elseif (pb_backupbuddy::_POST('#type') == 'local') {
// Used for automatic migration currently.
if (!file_exists(pb_backupbuddy::_POST('path'))) {
pb_backupbuddy::$filesystem->mkdir(pb_backupbuddy::_POST('path'));
}
if (is_writable(pb_backupbuddy::_POST('path')) === true) {
if (pb_backupbuddy::_POST('url') == '') {
// No URL provided.
echo __('Test completed successfully without URL. You may enter it on the next page.', 'it-l10n-backupbuddy');
} else {
// URL provided.
if (file_exists(rtrim(pb_backupbuddy::_POST('path'), '/\\') . '/wp-login.php')) {
echo 'Warning: WordPress appears to already exist in this location. ';
}
$test_filename = 'migrate_test_' . pb_backupbuddy::random_string(10) . '.php';
$test_file_path = rtrim(pb_backupbuddy::_POST('path'), '/\\') . '/' . $test_filename;
file_put_contents($test_file_path, "<?php die( '1' ); ?>");
$response = wp_remote_get(rtrim(pb_backupbuddy::_POST('url'), '/\\') . '/' . $test_filename, array('method' => 'GET', 'timeout' => 45, 'redirection' => 5, 'httpversion' => '1.0', 'blocking' => true, 'headers' => array(), 'body' => null, 'cookies' => array()));
unlink($test_file_path);
if (is_wp_error($response)) {
die(__('Failure. Unable to connect to the provided URL.', 'it-l10n-backupbuddy'));
}
if (trim($response['body']) == '1') {
echo __('Test completed successfully. Path and URL appear valid and match.', 'it-l10n-backupbuddy');
} else {
echo __('Failure. The path appears valid but the URL does not correspond to it.', 'it-l10n-backupbuddy');
}
}
} else {
echo __('Failure', 'it-l10n-backupbuddy') . '; The path does not allow writing. Please verify write file permissions.';
}
} else {
echo 'Error #4343489. There is not an automated test available for this service `' . $_POST['#type'] . '` at this time.';
}
die;
}
示例7: __construct
function __construct($save_point, $default_options_point)
{
$this->_save_point = $save_point;
$this->_default_options_point = $default_options_point;
$this->_instance = pb_backupbuddy::random_string();
}
示例8: test
public static function test($settings)
{
$settings = self::_init($settings);
// Try sending a file.
$send_response = pb_backupbuddy_destinations::send($settings, dirname(dirname(__FILE__)) . '/remote-send-test.php', $send_id = 'TEST-' . pb_backupbuddy::random_string(12));
// 3rd param true forces clearing of any current uploads.
if (false === $send_response) {
$send_response = 'Error sending test file to S3.';
} else {
$send_response = 'Success.';
}
// Delete sent file.
$delete_response = 'Success.';
try {
$delete_response = self::$_client->delete_object(array('Bucket' => $settings['bucket'], 'Key' => $settings['directory'] . 'remote-send-test.php'));
$delete_response = 'Success.';
} catch (Exception $e) {
pb_backupbuddy::status('details', 'Unable to delete test S3 file `remote-send-test.php`. Details: `' . $e->getMessage() . '`.');
}
// Load destination fileoptions.
pb_backupbuddy::status('details', 'About to load fileoptions data.');
require_once pb_backupbuddy::plugin_path() . '/classes/fileoptions.php';
pb_backupbuddy::status('details', 'Fileoptions instance #7.');
$fileoptions_obj = new pb_backupbuddy_fileoptions(backupbuddy_core::getLogDirectory() . 'fileoptions/send-' . $send_id . '.txt', $read_only = false, $ignore_lock = false, $create_file = false);
if (true !== ($result = $fileoptions_obj->is_ok())) {
return self::_error(__('Fatal Error #9034.84838. Unable to access fileoptions data.', 'it-l10n-backupbuddy') . ' Error: ' . $result);
}
pb_backupbuddy::status('details', 'Fileoptions data loaded.');
$fileoptions =& $fileoptions_obj->options;
if ('Success.' != $send_response || 'Success.' != $delete_response) {
$fileoptions['status'] = 'failure';
$fileoptions_obj->save();
unset($fileoptions_obj);
return 'Send details: `' . $send_response . '`. Delete details: `' . $delete_response . '`.';
} else {
$fileoptions['status'] = 'success';
$fileoptions['finish_time'] = time();
}
$fileoptions_obj->save();
unset($fileoptions_obj);
return true;
}
示例9: generate_key
public static function generate_key()
{
if (!defined('BACKUPBUDDY_API_ENABLE') || TRUE != BACKUPBUDDY_API_ENABLE) {
return false;
}
/*
if ( ! defined( 'BACKUPBUDDY_API_SALT' ) || ( 'CHANGEME' == BACKUPBUDDY_API_SALT ) || ( strlen( BACKUPBUDDY_API_SALT ) < 5 ) ) {
return false;
}
*/
$siteurl = site_url();
$homeurl = home_url();
$rand = pb_backupbuddy::random_string(12);
$rand2 = pb_backupbuddy::random_string(12);
$key = array('key_version' => 1, 'key_public' => md5($rand . pb_backupbuddy::$options['log_serial'] . $siteurl . $homeurl . time()), 'key_secret' => md5($rand2 . pb_backupbuddy::$options['log_serial'] . $siteurl . $homeurl . time()), 'key_created' => time(), 'siteurl' => $siteurl, 'homeurl' => $homeurl);
return base64_encode(json_encode($key));
}
示例10: _e
_e('Deployment', 'it-l10n-backupbuddy');
?>
</h3>
Remote API Access allows other sites with your API access key entered to push to or pull data from this site.
<br><br>
<button class="button button-primary" style="vertical-align: 1px;" onClick="jQuery('.backupbuddy_api_wpconfig-hide').toggle(); jQuery(this).hide(); return false;"><?php
_e('Enable Deployment', 'it-l10n-backupbuddy');
?>
</button>
<span class="backupbuddy_api_wpconfig-hide" style="display: none;">
<b>For added security you must manually <i>add the following to your wp-config.php</i> file to enable. <i>Refresh this page after adding</i> the following:</b>
<br>
<textarea style="width: 100%; padding: 15px;" readonly="readonly" onClick="this.focus();this.select();">
define( 'BACKUPBUDDY_API_ENABLE', true ); // Enable BackupBuddy Deployment access.
</textarea><!-- define( 'BACKUPBUDDY_API_SALT', '<?php
echo pb_backupbuddy::random_string(32);
?>
' ); // Random security identifier. 5+ characters. -->
</span>
<br>
<?php
}
}
echo '</div>';
echo '<div class="backupbuddy-destination-sends" style="display: none;"><br>';
require_once 'server_info/remote_sends.php';
echo '<br></div>';
echo '<iframe id="pb_backupbuddy_iframe-dest-wrap" src="' . pb_backupbuddy::ajax_url('destinationTabs') . '&tab=' . $default_tab . '&action_verb=to%20manage%20files" width="100%" height="4000" frameBorder="0">Error #4584594579. Browser not compatible with iframes.</iframe>';
?>
<br style="clear: both;"><br style="clear: both;">
示例11: send_remote_destination
function send_remote_destination($destination_id, $file, $trigger = '', $send_importbuddy = false)
{
pb_backupbuddy::status('details', 'Sending file `' . $file . '` to remote destination `' . $destination_id . '` triggered by `' . $trigger . '`.');
if (defined('PB_DEMO_MODE')) {
return false;
}
// Record some statistics.
$identifier = pb_backupbuddy::random_string(12);
pb_backupbuddy::$options['remote_sends'][$identifier] = array('destination' => $destination_id, 'file' => $file, 'file_size' => filesize($file), 'trigger' => $trigger, 'send_importbuddy' => $send_importbuddy, 'start_time' => time(), 'finish_time' => 0, 'status' => 'timeout');
pb_backupbuddy::save();
// Prepare variables to pass to remote destination handler.
$files = array($file);
$destination_settings =& pb_backupbuddy::$options['remote_destinations'][$destination_id];
// For Stash we will check the quota prior to initiating send.
if (pb_backupbuddy::$options['remote_destinations'][$destination_id]['type'] == 'stash') {
// Pass off to destination handler.
require_once pb_backupbuddy::plugin_path() . '/destinations/bootstrap.php';
$send_result = pb_backupbuddy_destinations::get_info('stash');
// Used to kick the Stash destination into life.
$stash_quota = pb_backupbuddy_destination_stash::get_quota(pb_backupbuddy::$options['remote_destinations'][$destination_id], true);
if ($file != '') {
$backup_file_size = filesize($file);
} else {
$backip_file_size = 50000;
}
if ($backup_file_size + $stash_quota['quota_used'] > $stash_quota['quota_total']) {
$message = '';
$message .= "You do not have enough Stash storage space to send this file. Please upgrade your Stash storage at http://ithemes.com/member/stash.php or delete files to make space.\n\n";
$message .= 'Attempting to send file of size ' . pb_backupbuddy::$format->file_size($backup_file_size) . ' but you only have ' . $stash_quota['quota_available_nice'] . ' available. ';
$message .= 'Currently using ' . $stash_quota['quota_used_nice'] . ' of ' . $stash_quota['quota_total_nice'] . ' (' . $stash_quota['quota_used_percent'] . '%).';
pb_backupbuddy::status('error', $message);
pb_backupbuddy::$classes['core']->mail_error($message);
pb_backupbuddy::$options['remote_sends'][$identifier]['status'] = 'Failure. Insufficient destination space.';
pb_backupbuddy::save();
return false;
} else {
if (isset($stash_quota['quota_warning']) && $stash_quota['quota_warning'] != '') {
// We log warning of usage but dont send error email.
$message = '';
$message .= 'WARNING: ' . $stash_quota['quota_warning'] . "\n\nPlease upgrade your Stash storage at http://ithemes.com/member/stash.php or delete files to make space.\n\n";
$message .= 'Currently using ' . $stash_quota['quota_used_nice'] . ' of ' . $stash_quota['quota_total_nice'] . ' (' . $stash_quota['quota_used_percent'] . '%).';
pb_backupbuddy::status('details', $message);
//pb_backupbuddy::$classes['core']->mail_error( $message );
}
}
}
if ($send_importbuddy === true) {
pb_backupbuddy::status('details', 'Generating temporary importbuddy.php file for remote send.');
$importbuddy_temp = pb_backupbuddy::$options['temp_directory'] . 'importbuddy.php';
// Full path & filename to temporary importbuddy
$this->importbuddy($importbuddy_temp);
// Create temporary importbuddy.
pb_backupbuddy::status('details', 'Generated temporary importbuddy.');
$files[] = $importbuddy_temp;
// Add importbuddy file to the list of files to send.
$send_importbuddy = true;
// Track to delete after finished.
} else {
pb_backupbuddy::status('details', 'Not sending importbuddy.');
}
// Pass off to destination handler.
require_once pb_backupbuddy::plugin_path() . '/destinations/bootstrap.php';
$send_result = pb_backupbuddy_destinations::send($destination_settings, $files);
$this->kick_db();
// Kick the database to make sure it didn't go away, preventing options saving.
// Update stats.
pb_backupbuddy::$options['remote_sends'][$identifier]['finish_time'] = time();
if ($send_result === true) {
// succeeded.
pb_backupbuddy::$options['remote_sends'][$identifier]['status'] = 'success';
pb_backupbuddy::status('details', 'Remote send SUCCESS.');
} elseif ($send_result === false) {
// failed.
pb_backupbuddy::$options['remote_sends'][$identifier]['status'] = 'failure';
pb_backupbuddy::status('details', 'Remote send FAILURE.');
} elseif (is_array($send_result)) {
// Array so multipart.
pb_backupbuddy::$options['remote_sends'][$identifier]['status'] = 'multipart';
pb_backupbuddy::$options['remote_sends'][$identifier]['finish_time'] = 0;
pb_backupbuddy::$options['remote_sends'][$identifier]['_multipart_id'] = $send_result[0];
pb_backupbuddy::$options['remote_sends'][$identifier]['_multipart_status'] = $send_result[1];
pb_backupbuddy::status('details', 'Multipart send in progress.');
} else {
pb_backupbuddy::status('error', 'Error #5485785576463. Invalid status send result: `' . $send_result . '`.');
}
pb_backupbuddy::save();
// If we sent importbuddy then delete the local copy to clean up.
if ($send_importbuddy !== false) {
@unlink($importbuddy_temp);
// Delete temporary importbuddy.
}
return $send_result;
}
示例12: test
public static function test($settings)
{
if ($settings['address'] == '' || $settings['username'] == '' || $settings['password'] == '') {
return __('Missing required input.', 'it-l10n-backupbuddy');
}
// Try sending a file.
$send_response = pb_backupbuddy_destinations::send($settings, dirname(dirname(__FILE__)) . '/remote-send-test.php', $send_id = 'TEST-' . pb_backupbuddy::random_string(12));
// 3rd param true forces clearing of any current uploads.
if (false === $send_response) {
$send_response = 'Error sending test file to FTP.';
} else {
$send_response = 'Success.';
}
// Now we will need to go and cleanup this potentially uploaded file.
$delete_response = 'Error deleting test file from FTP.';
// Default.
// Settings.
$server = $settings['address'];
$username = $settings['username'];
$password = $settings['password'];
$path = $settings['path'];
$ftps = $settings['ftps'];
if ($settings['active_mode'] == '0') {
$active_mode = false;
} else {
$active_mode = true;
}
$url = $settings['url'];
// optional url for using with migration.
$port = '21';
if (strstr($server, ':')) {
$server_params = explode(':', $server);
$server = $server_params[0];
$port = $server_params[1];
}
// Connect.
if ($ftps == '0') {
$conn_id = @ftp_connect($server, $port, 10);
// timeout of 10 seconds.
if ($conn_id === false) {
$error = __('Unable to connect to FTP address `' . $server . '` on port `' . $port . '`.', 'it-l10n-backupbuddy');
$error .= "\n" . __('Verify the server address and port (default 21). Verify your host allows outgoing FTP connections.', 'it-l10n-backupbuddy');
return $send_response . ' ' . $error;
}
} else {
if (function_exists('ftp_ssl_connect')) {
$conn_id = @ftp_ssl_connect($server, $port);
if ($conn_id === false) {
return $send_response . ' ' . __('Destination server does not support FTPS?', 'it-l10n-backupbuddy');
}
} else {
return $send_response . ' ' . __('Your web server doesnt support FTPS.', 'it-l10n-backupbuddy');
}
}
$login_result = @ftp_login($conn_id, $username, $password);
if (!$conn_id || !$login_result) {
pb_backupbuddy::status('details', 'FTP test: Invalid user/pass.');
$response = __('Unable to login. Bad user/pass.', 'it-l10n-backupbuddy');
if ($ftps != '0') {
$response .= "\n\nNote: You have FTPs enabled. You may get this error if your host does not support encryption at this address/port.";
}
return $send_response . ' ' . $response;
}
pb_backupbuddy::status('details', 'FTP test: Success logging in.');
// Handle active/pasive mode.
if ($active_mode === true) {
// do nothing, active is default.
pb_backupbuddy::status('details', 'Active FTP mode based on settings.');
} elseif ($active_mode === false) {
// Turn passive mode on.
pb_backupbuddy::status('details', 'Passive FTP mode based on settings.');
ftp_pasv($conn_id, true);
} else {
pb_backupbuddy::status('error', 'Unknown FTP active/passive mode: `' . $active_mode . '`.');
}
// Delete test file.
pb_backupbuddy::status('details', 'FTP test: Deleting temp test file.');
if (true === ftp_delete($conn_id, $path . '/remote-send-test.php')) {
$delete_response = 'Success.';
}
// Close FTP connection.
pb_backupbuddy::status('details', 'FTP test: Closing FTP connection.');
@ftp_close($conn_id);
// Load destination fileoptions.
pb_backupbuddy::status('details', 'About to load fileoptions data.');
require_once pb_backupbuddy::plugin_path() . '/classes/fileoptions.php';
pb_backupbuddy::status('details', 'Fileoptions instance #12.');
$fileoptions_obj = new pb_backupbuddy_fileoptions(backupbuddy_core::getLogDirectory() . 'fileoptions/send-' . $send_id . '.txt', $read_only = false, $ignore_lock = false, $create_file = false);
if (true !== ($result = $fileoptions_obj->is_ok())) {
pb_backupbuddy::status('error', __('Fatal Error #9034.72373. Unable to access fileoptions data.', 'it-l10n-backupbuddy') . ' Error: ' . $result);
return false;
}
pb_backupbuddy::status('details', 'Fileoptions data loaded.');
$fileoptions =& $fileoptions_obj->options;
if ('Success.' != $send_response || 'Success.' != $delete_response) {
$fileoptions['status'] = 'failure';
$fileoptions_obj->save();
unset($fileoptions_obj);
return 'Send details: `' . $send_response . '`. Delete details: `' . $delete_response . '`.';
} else {
//.........这里部分代码省略.........
示例13: process_backup
function process_backup($serial, $trigger = 'manual')
{
pb_backupbuddy::status('details', 'Running process_backup() for serial `' . $serial . '`.');
// Assign reference to backup data structure for this backup.
$this->_backup =& pb_backupbuddy::$options['backups'][$serial];
$found_next_step = false;
foreach ($this->_backup['steps'] as &$step) {
// Loop through steps finding first step that has not run.
if ($step['start_time'] != 0 && $step['finish_time'] == 0) {
// A step has begun but has not finished. This should not happen but the WP cron is funky. Wait a while before continuing.
$step['attempts']++;
// Increment this as an attempt.
pb_backupbuddy::save();
if ($step['attempts'] < 6) {
$wait_time = 60 * $step['attempts'];
// Each attempt adds a minute of wait time.
pb_backupbuddy::status('message', 'A scheduled step attempted to run before the previous step completed. Waiting `' . $wait_time . '` seconds before continuining for it to catch up. Attempt number `' . $step['attempts'] . '`.');
$this->cron_next_step(false, $wait_time);
return false;
} else {
// Too many attempts to run this step.
pb_backupbuddy::status('error', 'A scheduled step attempted to run before the previous step completed. After several attempts (`' . $step['attempts'] . '`) of failure BackupBuddy has given up. Halting backup.');
return false;
}
break;
} elseif ($step['start_time'] == 0) {
// Step that has not started yet.
$found_next_step = true;
$step['start_time'] = time();
// Set this step time to now.
$step['attempts']++;
// Increment this as an attempt.
pb_backupbuddy::save();
pb_backupbuddy::status('details', 'Found next step to run: `' . $step['function'] . '`.');
break;
} else {
// Last case: Finished. Skip.
// Do nothing for completed steps.
}
}
// End foreach().
if ($found_next_step === false) {
// No more steps to perform; return.
return false;
}
pb_backupbuddy::save();
pb_backupbuddy::status('details', __('Peak memory usage', 'it-l10n-backupbuddy') . ': ' . round(memory_get_peak_usage() / 1048576, 3) . ' MB');
/********* Begin Running Step Function **********/
if (method_exists($this, $step['function'])) {
pb_backupbuddy::status('details', 'Starting function `' . $step['function'] . '` now (' . time() . ').');
$response = call_user_func_array(array(&$this, $step['function']), $step['args']);
} else {
pb_backupbuddy::status('error', __('Error #82783745: Invalid function `' . $step['function'] . '`'));
$response = false;
}
/********* End Running Step Function **********/
if ($response === false) {
// Function finished but reported failure.
pb_backupbuddy::status('error', 'Failed function `' . $step['function'] . '`. Backup terminated.');
pb_backupbuddy::status('details', __('Peak memory usage', 'it-l10n-backupbuddy') . ': ' . round(memory_get_peak_usage() / 1048576, 3) . ' MB');
pb_backupbuddy::status('action', 'halt_script');
// Halt JS on page.
if (pb_backupbuddy::$options['log_level'] == '3') {
$debugging = "\n\n\n\n\n\nDebugging information sent due to error logging set to high debugging mode: \n\n" . pb_backupbuddy::random_string(10) . base64_encode(print_r(debug_backtrace(), true)) . "\n\n";
} else {
$debugging = '';
}
pb_backupbuddy::$classes['core']->mail_error('One or more backup steps reported a failure. Backup failure running function `' . $step['function'] . '` with the arguments `' . implode(',', $step['args']) . '` with backup serial `' . $serial . '`. Please run a manual backup of the same type to verify backups are working properly.' . $debugging);
return false;
} else {
// Function finished successfully.
$step['finish_time'] = time();
$this->_backup['updated_time'] = time();
pb_backupbuddy::save();
pb_backupbuddy::status('details', sprintf(__('Finished function `%s`.', 'it-l10n-backupbuddy'), $step['function']));
pb_backupbuddy::status('details', __('Peak memory usage', 'it-l10n-backupbuddy') . ': ' . round(memory_get_peak_usage() / 1048576, 3) . ' MB');
$found_another_step = false;
foreach ($this->_backup['steps'] as $next_step) {
// Loop through each step and see if any have not started yet.
if ($next_step['start_time'] == 0) {
// Another unstarted step exists. Schedule it.
$found_another_step = true;
if (pb_backupbuddy::$options['backup_mode'] == '2' || $trigger == 'scheduled') {
$this->cron_next_step();
} else {
// classic mode
$this->process_backup($this->_backup['serial'], $trigger);
}
break;
}
}
// End foreach().
if ($found_another_step == false) {
pb_backupbuddy::status('details', 'Finished backup at ' . pb_backupbuddy::$format->date(time()) . ' (' . time() . ').');
$this->_backup['finish_time'] = time();
pb_backupbuddy::save();
}
return true;
}
}
示例14: send_remote_destination
public static function send_remote_destination($destination_id, $file, $trigger = '', $send_importbuddy = false, $delete_after = false, $identifier = '', $destination_settings = '')
{
if (defined('PB_DEMO_MODE')) {
return false;
}
if (!file_exists($file)) {
pb_backupbuddy::status('error', 'Error #8583489734: Unable to send file `' . $file . '` to remote destination as it no longer exists. It may have been deleted or permissions are invalid.');
return false;
}
$migrationkey_transient_time = 60 * 60 * 24;
if ('' == $file) {
$backup_file_size = 50000;
// not sure why anything current would be sending importbuddy but NOT sending a backup but just in case...
} else {
$backup_file_size = filesize($file);
}
// Generate remote send ID for reference and add it as a new logging serial for better recording details.
if ('' == $identifier) {
$identifier = pb_backupbuddy::random_string(12);
}
// Set migration key for later determining last initiated migration.
if ('migration' == $trigger) {
set_transient('pb_backupbuddy_migrationkey', $identifier, $migrationkey_transient_time);
}
pb_backupbuddy::status('details', 'Sending file `' . $file . '` to remote destination `' . $destination_id . '` triggered by `' . $trigger . '`.');
//pb_backupbuddy::status( 'details', 'About to create initial fileoptions data.' );
require_once pb_backupbuddy::plugin_path() . '/classes/fileoptions.php';
pb_backupbuddy::status('details', 'Fileoptions instance #35.');
$fileoptions_obj = new pb_backupbuddy_fileoptions(backupbuddy_core::getLogDirectory() . 'fileoptions/send-' . $identifier . '.txt', $read_only = false, $ignore_lock = true, $create_file = true);
if (true !== ($result = $fileoptions_obj->is_ok())) {
pb_backupbuddy::status('error', __('Fatal Error #9034 A. Unable to access fileoptions data.', 'it-l10n-backupbuddy') . ' Error: ' . $result);
return false;
}
//pb_backupbuddy::status( 'details', 'Fileoptions data loaded.' );
$fileoptions =& $fileoptions_obj->options;
// Set reference.
// Record some statistics.
$fileoptions = array_merge(self::get_remote_send_defaults(), array('destination' => $destination_id, 'file' => $file, 'file_size' => $backup_file_size, 'trigger' => $trigger, 'send_importbuddy' => $send_importbuddy, 'start_time' => time(), 'finish_time' => 0, 'status' => 'timeout', 'write_speed' => 0));
pb_backupbuddy::save();
// Prepare variables to pass to remote destination handler.
if ('' == $file) {
// No file to send (blank string file typically happens when just sending importbuddy).
$files = array();
} else {
$files = array($file);
}
// Destination settings were not passed so get them based on the destination ID provided.
if (!is_array($destination_settings)) {
$destination_settings =& pb_backupbuddy::$options['remote_destinations'][$destination_id];
}
// For Stash we will check the quota prior to initiating send.
if (pb_backupbuddy::$options['remote_destinations'][$destination_id]['type'] == 'stash') {
// Pass off to destination handler.
require_once pb_backupbuddy::plugin_path() . '/destinations/bootstrap.php';
$send_result = pb_backupbuddy_destinations::get_info('stash');
// Used to kick the Stash destination into life.
$stash_quota = pb_backupbuddy_destination_stash::get_quota(pb_backupbuddy::$options['remote_destinations'][$destination_id], true);
if ($file != '') {
$backup_file_size = filesize($file);
} else {
$backup_file_size = 50000;
}
if ($backup_file_size + $stash_quota['quota_used'] > $stash_quota['quota_total']) {
$message = '';
$message .= "You do not have enough Stash storage space to send this file. Please upgrade your Stash storage at http://ithemes.com/member/panel/stash.php or delete files to make space.\n\n";
$message .= 'Attempting to send file of size ' . pb_backupbuddy::$format->file_size($backup_file_size) . ' but you only have ' . $stash_quota['quota_available_nice'] . ' available. ';
$message .= 'Currently using ' . $stash_quota['quota_used_nice'] . ' of ' . $stash_quota['quota_total_nice'] . ' (' . $stash_quota['quota_used_percent'] . '%).';
pb_backupbuddy::status('error', $message);
backupbuddy_core::mail_error($message);
$fileoptions['status'] = 'Failure. Insufficient destination space.';
$fileoptions_obj->save();
return false;
} else {
if (isset($stash_quota['quota_warning']) && $stash_quota['quota_warning'] != '') {
// We log warning of usage but dont send error email.
$message = '';
$message .= 'WARNING: ' . $stash_quota['quota_warning'] . "\n\nPlease upgrade your Stash storage at http://ithemes.com/member/panel/stash.php or delete files to make space.\n\n";
$message .= 'Currently using ' . $stash_quota['quota_used_nice'] . ' of ' . $stash_quota['quota_total_nice'] . ' (' . $stash_quota['quota_used_percent'] . '%).';
pb_backupbuddy::status('details', $message);
//backupbuddy_core::mail_error( $message );
}
}
}
if ($send_importbuddy === true) {
pb_backupbuddy::status('details', 'Generating temporary importbuddy.php file for remote send.');
pb_backupbuddy::anti_directory_browsing(backupbuddy_core::getTempDirectory(), $die = false);
$importbuddy_temp = backupbuddy_core::getTempDirectory() . 'importbuddy.php';
// Full path & filename to temporary importbuddy
self::importbuddy($importbuddy_temp);
// Create temporary importbuddy.
pb_backupbuddy::status('details', 'Generated temporary importbuddy.');
$files[] = $importbuddy_temp;
// Add importbuddy file to the list of files to send.
$send_importbuddy = true;
// Track to delete after finished.
} else {
pb_backupbuddy::status('details', 'Not sending importbuddy.');
}
// Clear fileoptions so other stuff can access it if needed.
$fileoptions_obj->save();
//.........这里部分代码省略.........
示例15: test
public static function test($settings)
{
$settings = self::_normalizeSettings($settings);
if (false === ($settings = self::_connect($settings))) {
$error = 'Unable to connect with Google Drive. See log for details.';
echo $error;
pb_backupbuddy::status('error', $error);
return false;
}
pb_backupbuddy::status('details', 'Testing Google Drive destination. Sending ImportBuddy.php.');
pb_backupbuddy::anti_directory_browsing(backupbuddy_core::getTempDirectory(), $die = false);
$importbuddy_temp = backupbuddy_core::getTempDirectory() . 'importbuddy_' . pb_backupbuddy::random_string(10) . '.php.tmp';
// Full path & filename to temporary importbuddy
backupbuddy_core::importbuddy($importbuddy_temp);
// Create temporary importbuddy.
$files = array($importbuddy_temp);
$results = self::send($settings, $files, '', $delete_remote_after = true);
@unlink($importbuddy_temp);
if (true === $results) {
echo 'Success sending test file to Google Drive. ';
return true;
} else {
global $pb_backupbuddy_destination_errors;
echo 'Failure sending test file to Google Drive. Details: `' . implode(', ', $pb_backupbuddy_destination_errors) . '`.';
return false;
}
}