PageRenderTime 49ms CodeModel.GetById 9ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/backupbuddy/classes/core.php

https://bitbucket.org/betaimages/chakalos
PHP | 1756 lines | 1201 code | 306 blank | 249 comment | 229 complexity | f039ce688c796a7fa660be131f30766e MD5 | raw file
Possible License(s): BSD-3-Clause

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. // Helper functions for BackupBuddy.
  3. // TODO: Eventually break out of a lot of these from BB core. Migrating from old framework to new resulted in this mid-way transition but it's a bit messy...
  4. class pb_backupbuddy_core {
  5. /* is_network_activated()
  6. *
  7. * Returns a boolean indicating whether a plugin is network activated or not.
  8. *
  9. * @return boolean True if plugin is network activated, else false.
  10. */
  11. function is_network_activated() {
  12. if ( !function_exists( 'is_plugin_active_for_network' ) ) { // Function is not available on all WordPress pages for some reason according to codex.
  13. require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
  14. }
  15. if ( is_plugin_active_for_network( basename( pb_backupbuddy::plugin_path() ) . '/' . pb_backupbuddy::settings( 'init' ) ) ) { // Path relative to wp-content\plugins\ directory.
  16. return true;
  17. } else {
  18. return false;
  19. }
  20. } // End is_network_activated().
  21. /* backup_integrity_check()
  22. *
  23. * Scans a backup file and saves the result in data structure. Checks for key files & that .zip can be read properly. Stores results with details in data structure.
  24. *
  25. * @param string $file Full pathname & filename to backup file to check.
  26. * @return boolean True if integrity 100% passed, else false. ( Side note: Result details stored in pb_backupbuddy::$options['backups'][$serial]['integrity'] ).
  27. */
  28. function backup_integrity_check( $file ) {
  29. $serial = $this->get_serial_from_file( $file );
  30. // User selected to rescan a file.
  31. if ( pb_backupbuddy::_GET( 'reset_integrity' ) == $serial ) {
  32. pb_backupbuddy::alert( 'Rescanning backup integrity for backup file `' . basename( $file ) . '`' );
  33. }
  34. if ( isset( pb_backupbuddy::$options['backups'][$serial]['integrity'] ) && ( count( pb_backupbuddy::$options['backups'][$serial]['integrity'] ) > 0 ) && ( pb_backupbuddy::_GET( 'reset_integrity' ) != $serial ) ) { // Already have integrity data and NOT resetting this one.
  35. pb_backupbuddy::status( 'details', 'Integrity data for backup `' . $serial . '` is cached; not scanning again.' );
  36. return;
  37. } elseif ( pb_backupbuddy::_GET( 'reset_integrity' ) == $serial ) { // Resetting this one.
  38. pb_backupbuddy::status( 'details', 'Resetting backup integrity stats for backup with serial `' . $serial . '`.' );
  39. }
  40. if ( pb_backupbuddy::$options['integrity_check'] == '0' ) { // Integrity checking disabled.
  41. $file_stats = @stat( $file );
  42. if ( $file_stats === false ) { // stat failure.
  43. pb_backupbuddy::alert( 'Error #4539774. Unable to get file details ( via stat() ) for file `' . $file . '`. The file may be corrupt or too large for the server.' );
  44. $file_size = 0;
  45. $file_modified = 0;
  46. } else { // stat success.
  47. $file_size = $file_stats['size'];
  48. $file_modified = $file_stats['mtime'];
  49. }
  50. unset( $file_stats );
  51. $integrity = array(
  52. 'status' => 'Unknown',
  53. 'status_details' => __( 'Integrity checking disabled based on settings. This file has not been verified.', 'it-l10n-backupbuddy' ),
  54. 'scan_time' => 0,
  55. 'detected_type' => 'unknown',
  56. 'size' => $file_size,
  57. 'modified' => $file_modified,
  58. 'file' => basename( $file ),
  59. 'comment' => false,
  60. );
  61. pb_backupbuddy::$options['backups'][$serial]['integrity'] = array_merge( pb_backupbuddy::settings( 'backups_integrity_defaults' ), $integrity );
  62. pb_backupbuddy::save();
  63. return;
  64. }
  65. //***** BEGIN CALCULATING STATUS DETAILS.
  66. // Status defaults.
  67. $status_details = array(
  68. 'found_dat' => false,
  69. 'found_sql' => false,
  70. 'found_wpconfig' => false,
  71. 'scan_log' => '',
  72. );
  73. $backup_type = '';
  74. if ( !isset( pb_backupbuddy::$classes['zipbuddy'] ) ) {
  75. require_once( pb_backupbuddy::plugin_path() . '/lib/zipbuddy/zipbuddy.php' );
  76. pb_backupbuddy::$classes['zipbuddy'] = new pluginbuddy_zipbuddy( pb_backupbuddy::$options['backup_directory'] );
  77. }
  78. pb_backupbuddy::set_status_serial( 'zipbuddy_test' ); // Redirect logging output to a certain log file.
  79. // Look for comment.
  80. $comment = pb_backupbuddy::$classes['zipbuddy']->get_comment( $file );
  81. // Check for DAT file.
  82. if ( pb_backupbuddy::$classes['zipbuddy']->file_exists( $file, 'wp-content/uploads/backupbuddy_temp/' . $serial . '/backupbuddy_dat.php' ) === true ) { // Post 2.0 full backup
  83. $status_details['found_dat'] = true;
  84. $backup_type = 'full';
  85. }
  86. if ( pb_backupbuddy::$classes['zipbuddy']->file_exists( $file, 'wp-content/uploads/temp_' . $serial . '/backupbuddy_dat.php' ) === true ) { // Pre 2.0 full backup
  87. $status_details['found_dat'] = true;
  88. $backup_type = 'full';
  89. }
  90. if ( pb_backupbuddy::$classes['zipbuddy']->file_exists( $file, 'backupbuddy_dat.php' ) === true ) { // DB backup
  91. $status_details['found_dat'] = true;
  92. $backup_type = 'db';
  93. }
  94. // Check for DB SQL file.
  95. if ( pb_backupbuddy::$classes['zipbuddy']->file_exists( $file, 'wp-content/uploads/backupbuddy_temp/' . $serial . '/db_1.sql' ) === true ) { // post 2.0 full backup
  96. $status_details['found_sql'] = true;
  97. $backup_type = 'full';
  98. }
  99. if ( pb_backupbuddy::$classes['zipbuddy']->file_exists( $file, 'wp-content/uploads/temp_' . $serial . '/db.sql' ) === true ) { // pre 2.0 full backup
  100. $status_details['found_sql'] = true;
  101. $backup_type = 'full';
  102. }
  103. if ( pb_backupbuddy::$classes['zipbuddy']->file_exists( $file, 'db_1.sql' ) === true ) { // db only backup 2.0+
  104. $status_details['found_sql'] = true;
  105. $backup_type = 'db';
  106. }
  107. if ( pb_backupbuddy::$classes['zipbuddy']->file_exists( $file, 'db.sql' ) === true ) { // db only backup pre-2.0
  108. $status_details['found_sql'] = true;
  109. $backup_type = 'db';
  110. }
  111. // Check for WordPress config file.
  112. if ( pb_backupbuddy::$classes['zipbuddy']->file_exists( $file, 'wp-config.php' ) === true ) {
  113. $status_details['found_wpconfig'] = true;
  114. $backup_type = 'full';
  115. }
  116. if ( pb_backupbuddy::$classes['zipbuddy']->file_exists( $file, 'wp-content/uploads/backupbuddy_temp/' . $serial . '/wp-config.php' ) === true ) {
  117. $status_details['found_wpconfig'] = true;
  118. $backup_type = 'full';
  119. }
  120. // Get zip scan log details.
  121. $temp_details = pb_backupbuddy::get_status( 'zipbuddy_test' ); // Get zipbuddy scan log.
  122. foreach( $temp_details as $temp_detail ) {
  123. $status_details['scan_log'][] = $temp_detail[4];
  124. }
  125. pb_backupbuddy::set_status_serial( '' ); // Stop redirecting log to a specific file.
  126. // Calculate status descriptions.
  127. $integrity_status = 'pass'; // Default.
  128. if ( $status_details['found_dat'] !== true ) {
  129. $integrity_status = 'fail';
  130. $integrity_description .= __('Error #7843564: Missing DAT file.', 'it-l10n-backupbuddy' );
  131. }
  132. if ( $status_details['found_sql'] !== true ) {
  133. $integrity_status = 'fail';
  134. $integrity_description .= __('Error #4664236: Missing database SQL file.', 'it-l10n-backupbuddy' );
  135. }
  136. if ( ( $backup_type == 'full' ) && ( $status_details['found_wpconfig'] !== true ) ) {
  137. $integrity_status = 'fail';
  138. $integrity_description .= __('Error #47834674: Missing wp-config.php file.', 'it-l10n-backupbuddy' );
  139. }
  140. if ( $integrity_status == 'pass' ) { // All tests passed.
  141. $integrity_description = __( 'All tests passed.', 'it-l10n-backupbuddy' );
  142. }
  143. //$integrity_description .= '<br><br>' . __('Technical Details', 'it-l10n-backupbuddy' ) . ':<br />' . $integrity_zipresult_details;
  144. //***** END CALCULATING STATUS DETAILS.
  145. // Get file information from file system.
  146. $file_stats = @stat( $file );
  147. if ( $file_stats === false ) { // stat failure.
  148. pb_backupbuddy::alert( 'Error #4539774b. Unable to get file details ( via stat() ) for file `' . $file . '`. The file may be corrupt or too large for the server.' );
  149. $file_size = 0;
  150. $file_modified = 0;
  151. } else { // stat success.
  152. $file_size = $file_stats['size'];
  153. $file_modified = $file_stats['ctime']; // Created time.
  154. }
  155. unset( $file_stats );
  156. // Compile array of results for saving into data structure.
  157. $integrity = array(
  158. 'status' => $integrity_status,
  159. 'status_details' => $status_details, // $integrity_description,
  160. 'scan_time' => time(),
  161. 'detected_type' => $backup_type,
  162. 'size' => $file_size,
  163. 'modified' => $file_modified, // Actually created time now.
  164. 'file' => basename( $file ),
  165. 'comment' => $comment, // boolean false if no comment. string if comment.
  166. );
  167. pb_backupbuddy::$options['backups'][$serial]['integrity'] = array_merge( pb_backupbuddy::settings( 'backups_integrity_defaults' ), $integrity );
  168. pb_backupbuddy::save();
  169. //pb_backupbuddy::$classes['zipbuddy']->clear_status();
  170. if ( $integrity_status == 'pass' ) { // 100% success
  171. return true;
  172. } else {
  173. return false;
  174. }
  175. } // End backup_integrity_check().
  176. /* get_serial_from_file()
  177. *
  178. * Returns the backup serial based on the filename.
  179. *
  180. * @param string $file Filename containing a serial to extract.
  181. * @return string Serial found.
  182. */
  183. public function get_serial_from_file( $file ) {
  184. $serial = strrpos( $file, '-' ) + 1;
  185. $serial = substr( $file, $serial, ( strlen( $file ) - $serial - 4 ) );
  186. return $serial;
  187. } // End get_serial_from_file().
  188. /**
  189. * versions_confirm()
  190. *
  191. * Check the version of an item and compare it to the minimum requirements BackupBuddy requires.
  192. *
  193. * @param string $type Optional. If left blank '' then all tests will be performed. Valid values: wordpress, php, ''.
  194. * @param boolean $notify Optional. Whether or not to alert to the screen (and throw error to log) of a version issue.\
  195. * @return boolean True if the selected type is a bad version
  196. */
  197. function versions_confirm( $type = '', $notify = false ) {
  198. $bad_version = false;
  199. if ( ( $type == 'wordpress' ) || ( $type == '' ) ) {
  200. global $wp_version;
  201. if ( version_compare( $wp_version, pb_backupbuddy::settings( 'wp_minimum' ), '<=' ) ) {
  202. if ( $notify === true ) {
  203. pb_backupbuddy::alert( sprintf( __('ERROR: BackupBuddy requires WordPress version %1$s or higher. You may experience unexpected behavior or complete failure in this environment. Please consider upgrading WordPress.', 'it-l10n-backupbuddy' ), $this->_wp_minimum) );
  204. pb_backupbuddy::log( 'Unsupported WordPress Version: ' . $wp_version , 'error' );
  205. }
  206. $bad_version = true;
  207. }
  208. }
  209. if ( ( $type == 'php' ) || ( $type == '' ) ) {
  210. if ( version_compare( PHP_VERSION, pb_backupbuddy::settings( 'php_minimum' ), '<=' ) ) {
  211. if ( $notify === true ) {
  212. pb_backupbuddy::alert( sprintf( __('ERROR: BackupBuddy requires PHP version %1$s or higher. You may experience unexpected behavior or complete failure in this environment. Please consider upgrading PHP.', 'it-l10n-backupbuddy' ), PHP_VERSION ) );
  213. pb_backupbuddy::log( 'Unsupported PHP Version: ' . PHP_VERSION , 'error' );
  214. }
  215. $bad_version = true;
  216. }
  217. }
  218. return $bad_version;
  219. } // End versions_confirm().
  220. /* get_directory_exclusions()
  221. *
  222. * Get sanitized directory exclusions. See important note below!
  223. * IMPORTANT NOTE: Cannot exclude the temp directory here as this is where SQL and DAT files are stored for inclusion in the backup archive.
  224. *
  225. * @return array Array of directories to exclude.
  226. */
  227. public static function get_directory_exclusions() {
  228. // Get initial array.
  229. $exclusions = trim( pb_backupbuddy::$options['excludes'] ); // Trim string.
  230. $exclusions = preg_split('/\n|\r|\r\n/', $exclusions ); // Break into array on any type of line ending.
  231. // Add additional internal exclusions.
  232. $exclusions[] = str_replace( rtrim( ABSPATH, '\\\/' ), '', pb_backupbuddy::$options['backup_directory'] ); // Exclude backup directory.
  233. $exclusions[] = '/wp-content/uploads/pb_backupbuddy/'; // BackupBuddy logs and junk.
  234. $exclusions[] = '/importbuddy/'; // Exclude importbuddy directory in root.
  235. $exclusions[] = '/importbuddy.php'; // Exclude importbuddy.php script in root.
  236. // Clean up & sanitize array.
  237. array_walk( $exclusions, create_function( '&$val', '$val = rtrim( trim( $val ), \'/\' );' ) ); // Apply trim to all items within.
  238. $exclusions = array_filter( $exclusions, 'strlen' ); // Remove any empty / blank lines.
  239. // IMPORTANT NOTE: Cannot exclude the temp directory here as this is where SQL and DAT files are stored for inclusion in the backup archive.
  240. return $exclusions;
  241. } // End get_directory_exclusions().
  242. /* mail_error()
  243. *
  244. * Sends an error email to the defined email address(es) on settings page.
  245. *
  246. * @param string $message Message to be included in the body of the email.
  247. * @return null
  248. */
  249. function mail_error( $message ) {
  250. if ( !isset( pb_backupbuddy::$options ) ) {
  251. pb_backupbuddy::load();
  252. }
  253. $subject = pb_backupbuddy::$options['email_notify_error_subject'];
  254. $body = pb_backupbuddy::$options['email_notify_error_body'];
  255. $replacements = array(
  256. '{site_url}' => site_url(),
  257. '{backupbuddy_version}' => pb_backupbuddy::settings( 'version' ),
  258. '{current_datetime}' => date(DATE_RFC822),
  259. '{message}' => $message
  260. );
  261. foreach( $replacements as $replace_key => $replacement ) {
  262. $subject = str_replace( $replace_key, $replacement, $subject );
  263. $body = str_replace( $replace_key, $replacement, $body );
  264. }
  265. $email = pb_backupbuddy::$options['email_notify_error'];
  266. pb_backupbuddy::status( 'error', 'Sending email error notification. Subject: `' . $subject . '`; body: `' . $body . '`; recipient(s): `' . $email . '`.' );
  267. if ( !empty( $email ) ) {
  268. wp_mail( $email, $subject, $body, 'From: '.$email."\r\n".'Reply-To: '.get_option('admin_email')."\r\n");
  269. }
  270. } // End mail_error().
  271. /* mail_notify_scheduled()
  272. *
  273. * Sends a message email to the defined email address(es) on settings page.
  274. *
  275. * @param string $start_or_complete Whether this is the notifcation for starting or completing. Valid values: start, complete
  276. * @param string $message Message to be included in the body of the email.
  277. * @return null
  278. */
  279. function mail_notify_scheduled( $serial, $start_or_complete, $message ) {
  280. if ( !isset( pb_backupbuddy::$options ) ) {
  281. pb_backupbuddy::load();
  282. }
  283. if ( $start_or_complete == 'start' ) {
  284. $email = pb_backupbuddy::$options['email_notify_scheduled_start'];
  285. $subject = pb_backupbuddy::$options['email_notify_scheduled_start_subject'];
  286. $body = pb_backupbuddy::$options['email_notify_scheduled_start_body'];
  287. $replacements = array(
  288. '{site_url}' => site_url(),
  289. '{backupbuddy_version}' => pb_backupbuddy::settings( 'version' ),
  290. '{current_datetime}' => date(DATE_RFC822),
  291. '{message}' => $message
  292. );
  293. } elseif ( $start_or_complete == 'complete' ) {
  294. $email = pb_backupbuddy::$options['email_notify_scheduled_complete'];
  295. $subject = pb_backupbuddy::$options['email_notify_scheduled_complete_subject'];
  296. $body = pb_backupbuddy::$options['email_notify_scheduled_complete_body'];
  297. $replacements = array(
  298. '{site_url}' => site_url(),
  299. '{backupbuddy_version}' => pb_backupbuddy::settings( 'version' ),
  300. '{current_datetime}' => date(DATE_RFC822),
  301. '{message}' => $message,
  302. '{backup_serial}' => $serial,
  303. '{download_link}' => pb_backupbuddy::ajax_url( 'download_archive' ) . '&backupbuddy_backup=' . basename( pb_backupbuddy::$options['backups'][$serial]['archive_file'] ),
  304. '{backup_file}' => basename( pb_backupbuddy::$options['backups'][$serial]['archive_file'] ),
  305. '{backup_size}' => pb_backupbuddy::$format->file_size( pb_backupbuddy::$options['backups'][$serial]['archive_size'] ),
  306. '{backup_type}' => pb_backupbuddy::$options['backups'][$serial]['type'],
  307. );
  308. } else {
  309. pb_backupbuddy::status( 'error', 'ERROR #54857845785: Fatally halted. Invalid schedule type. Expected `start` or `complete`. Got `' . $start_or_complete . '`.' );
  310. }
  311. foreach( $replacements as $replace_key => $replacement ) {
  312. $subject = str_replace( $replace_key, $replacement, $subject );
  313. $body = str_replace( $replace_key, $replacement, $body );
  314. }
  315. pb_backupbuddy::status( 'error', 'Sending email schedule notification. Subject: `' . $subject . '`; body: `' . $body . '`; recipient(s): `' . $email . '`.' );
  316. if ( !empty( $email ) ) {
  317. wp_mail( $email, $subject, $body, 'From: '.$email."\r\n".'Reply-To: '.get_option('admin_email')."\r\n");
  318. }
  319. } // End mail_notify_scheduled().
  320. /* backup_prefix()
  321. *
  322. * Strips all non-file-friendly characters from the site URL. Used in making backup zip filename.
  323. *
  324. * @return string The filename friendly converted site URL.
  325. */
  326. function backup_prefix() {
  327. $siteurl = site_url();
  328. $siteurl = str_replace( 'http://', '', $siteurl );
  329. $siteurl = str_replace( 'https://', '', $siteurl );
  330. $siteurl = str_replace( '/', '_', $siteurl );
  331. $siteurl = str_replace( '\\', '_', $siteurl );
  332. $siteurl = str_replace( '.', '_', $siteurl );
  333. $siteurl = str_replace( ':', '_', $siteurl ); // Alternative port from 80 is stored in the site url.
  334. $siteurl = str_replace( '~', '_', $siteurl ); // Strip ~.
  335. return $siteurl;
  336. } // End backup_prefix().
  337. /* send_remote_destination()
  338. *
  339. * function description
  340. *
  341. * @param int $destination_id ID number (index of the destinations array) to send it.
  342. * @param string $file Full file path of file to send.
  343. * @param string $trigger What triggered this backup. Valid values: scheduled, manual.
  344. * @param bool $send_importbuddy Whether or not importbuddy.php should also be sent with the file to destination.
  345. * @return bool Send status. true success, false failed.
  346. */
  347. function send_remote_destination( $destination_id, $file, $trigger = '', $send_importbuddy = false ) {
  348. pb_backupbuddy::status( 'details', 'Sending file `' . $file . '` to remote destination `' . $destination_id . '` triggered by `' . $trigger . '`.' );
  349. if ( defined( 'PB_DEMO_MODE' ) ) {
  350. return false;
  351. }
  352. // Record some statistics.
  353. $identifier = pb_backupbuddy::random_string( 12 );
  354. pb_backupbuddy::$options['remote_sends'][$identifier] = array(
  355. 'destination' => $destination_id,
  356. 'file' => $file,
  357. 'file_size' => filesize( $file ),
  358. 'trigger' => $trigger, // What triggered this backup. Valid values: scheduled, manual.
  359. 'send_importbuddy' => $send_importbuddy,
  360. 'start_time' => time(),
  361. 'finish_time' => 0,
  362. 'status' => 'timeout', // success, failure, timeout (default assumption if this is not updated in this PHP load)
  363. );
  364. pb_backupbuddy::save();
  365. // Prepare variables to pass to remote destination handler.
  366. $files = array( $file );
  367. $destination_settings = &pb_backupbuddy::$options['remote_destinations'][$destination_id];
  368. // For Stash we will check the quota prior to initiating send.
  369. if ( pb_backupbuddy::$options['remote_destinations'][$destination_id]['type'] == 'stash' ) {
  370. // Pass off to destination handler.
  371. require_once( pb_backupbuddy::plugin_path() . '/destinations/bootstrap.php' );
  372. $send_result = pb_backupbuddy_destinations::get_info( 'stash' ); // Used to kick the Stash destination into life.
  373. $stash_quota = pb_backupbuddy_destination_stash::get_quota( pb_backupbuddy::$options['remote_destinations'][$destination_id], true );
  374. if ( $file != '' ) {
  375. $backup_file_size = filesize( $file );
  376. } else {
  377. $backip_file_size = 50000;
  378. }
  379. if ( ( $backup_file_size + $stash_quota['quota_used'] ) > $stash_quota['quota_total'] ) {
  380. $message = '';
  381. $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";
  382. $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. ';
  383. $message .= 'Currently using ' . $stash_quota['quota_used_nice'] . ' of ' . $stash_quota['quota_total_nice'] . ' (' . $stash_quota['quota_used_percent'] . '%).';
  384. pb_backupbuddy::status( 'error', $message );
  385. pb_backupbuddy::$classes['core']->mail_error( $message );
  386. pb_backupbuddy::$options['remote_sends'][$identifier]['status'] = 'Failure. Insufficient destination space.';
  387. pb_backupbuddy::save();
  388. return false;
  389. } else {
  390. if ( isset( $stash_quota['quota_warning'] ) && ( $stash_quota['quota_warning'] != '' ) ) {
  391. // We log warning of usage but dont send error email.
  392. $message = '';
  393. $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";
  394. $message .= 'Currently using ' . $stash_quota['quota_used_nice'] . ' of ' . $stash_quota['quota_total_nice'] . ' (' . $stash_quota['quota_used_percent'] . '%).';
  395. pb_backupbuddy::status( 'details', $message );
  396. //pb_backupbuddy::$classes['core']->mail_error( $message );
  397. }
  398. }
  399. }
  400. if ( $send_importbuddy === true ) {
  401. pb_backupbuddy::status( 'details', 'Generating temporary importbuddy.php file for remote send.' );
  402. $importbuddy_temp = pb_backupbuddy::$options['temp_directory'] . 'importbuddy.php'; // Full path & filename to temporary importbuddy
  403. $this->importbuddy( $importbuddy_temp ); // Create temporary importbuddy.
  404. pb_backupbuddy::status( 'details', 'Generated temporary importbuddy.' );
  405. $files[] = $importbuddy_temp; // Add importbuddy file to the list of files to send.
  406. $send_importbuddy = true; // Track to delete after finished.
  407. } else {
  408. pb_backupbuddy::status( 'details', 'Not sending importbuddy.' );
  409. }
  410. // Pass off to destination handler.
  411. require_once( pb_backupbuddy::plugin_path() . '/destinations/bootstrap.php' );
  412. $send_result = pb_backupbuddy_destinations::send( $destination_settings, $files );
  413. $this->kick_db(); // Kick the database to make sure it didn't go away, preventing options saving.
  414. // Update stats.
  415. pb_backupbuddy::$options['remote_sends'][$identifier]['finish_time'] = time();
  416. if ( $send_result === true ) { // succeeded.
  417. pb_backupbuddy::$options['remote_sends'][$identifier]['status'] = 'success';
  418. pb_backupbuddy::status( 'details', 'Remote send SUCCESS.' );
  419. } elseif ( $send_result === false ) { // failed.
  420. pb_backupbuddy::$options['remote_sends'][$identifier]['status'] = 'failure';
  421. pb_backupbuddy::status( 'details', 'Remote send FAILURE.' );
  422. } elseif ( is_array( $send_result ) ) { // Array so multipart.
  423. pb_backupbuddy::$options['remote_sends'][$identifier]['status'] = 'multipart';
  424. pb_backupbuddy::$options['remote_sends'][$identifier]['finish_time'] = 0;
  425. pb_backupbuddy::$options['remote_sends'][$identifier]['_multipart_id'] = $send_result[0];
  426. pb_backupbuddy::$options['remote_sends'][$identifier]['_multipart_status'] = $send_result[1];
  427. pb_backupbuddy::status( 'details', 'Multipart send in progress.' );
  428. } else {
  429. pb_backupbuddy::status( 'error', 'Error #5485785576463. Invalid status send result: `' . $send_result . '`.' );
  430. }
  431. pb_backupbuddy::save();
  432. // If we sent importbuddy then delete the local copy to clean up.
  433. if ( $send_importbuddy !== false ) {
  434. @unlink( $importbuddy_temp ); // Delete temporary importbuddy.
  435. }
  436. return $send_result;
  437. } // End send_remote_destination().
  438. /* destination_send()
  439. *
  440. * Send file(s) to a destination. Pass full array of destination settings.
  441. *
  442. * @param array $destination_settings All settings for this destination for this action.
  443. * @param array $files Array of files to send (full path).
  444. * @return bool|array Bool true = success, bool false = fail, array = multipart transfer.
  445. */
  446. public function destination_send( $destination_settings, $files ) {
  447. // Pass off to destination handler.
  448. require_once( pb_backupbuddy::plugin_path() . '/destinations/bootstrap.php' );
  449. $send_result = pb_backupbuddy_destinations::send( $destination_settings, $files );
  450. return $send_result;
  451. } // End destination_send().
  452. /* backups_list()
  453. *
  454. * function description
  455. *
  456. * @param string $type Valid options: default, migrate
  457. * @param boolean $subsite_mode When in subsite mode only backups for that specific subsite will be listed.
  458. * @return
  459. */
  460. public function backups_list( $type = 'default', $subsite_mode = false ) {
  461. if ( pb_backupbuddy::_POST( 'bulk_action' ) == 'delete_backup' ) {
  462. $needs_save = false;
  463. pb_backupbuddy::verify_nonce( pb_backupbuddy::_POST( '_wpnonce' ) ); // Security check to prevent unauthorized deletions by posting from a remote place.
  464. $deleted_files = array();
  465. foreach( pb_backupbuddy::_POST( 'items' ) as $item ) {
  466. if ( file_exists( pb_backupbuddy::$options['backup_directory'] . $item ) ) {
  467. if ( @unlink( pb_backupbuddy::$options['backup_directory'] . $item ) === true ) {
  468. $deleted_files[] = $item;
  469. if ( count( pb_backupbuddy::$options['backups'] ) > 5 ) { // Keep a minimum number of backups in array for stats.
  470. $this_serial = $this->get_serial_from_file( $item );
  471. unset( pb_backupbuddy::$options['backups'][$this_serial] );
  472. $needs_save = true;
  473. }
  474. } else {
  475. pb_backupbuddy::alert( 'Error: Unable to delete backup file `' . $item . '`. Please verify permissions.', true );
  476. }
  477. } // End if file exists.
  478. } // End foreach.
  479. if ( $needs_save === true ) {
  480. pb_backupbuddy::save();
  481. }
  482. pb_backupbuddy::alert( __( 'Deleted backup(s):', 'it-l10n-backupbuddy' ) . ' ' . implode( ', ', $deleted_files ) );
  483. } // End if deleting backup(s).
  484. $backups = array();
  485. $backup_sort_dates = array();
  486. $files = glob( pb_backupbuddy::$options['backup_directory'] . 'backup*.zip' );
  487. if ( is_array( $files ) && !empty( $files ) ) { // For robustness. Without open_basedir the glob() function returns an empty array for no match. With open_basedir in effect the glob() function returns a boolean false for no match.
  488. $backup_prefix = $this->backup_prefix(); // Backup prefix for this site. Used for MS checking that this user can see this backup.
  489. foreach( $files as $file_id => $file ) {
  490. if ( ( $subsite_mode === true ) && is_multisite() ) { // If a Network and NOT the superadmin must make sure they can only see the specific subsite backups for security purposes.
  491. // Only allow viewing of their own backups.
  492. if ( !strstr( $file, $backup_prefix ) ) {
  493. unset( $files[$file_id] ); // Remove this backup from the list. This user does not have access to it.
  494. continue; // Skip processing to next file.
  495. }
  496. }
  497. $serial = pb_backupbuddy::$classes['core']->get_serial_from_file( $file );
  498. // Populate integrity data structure in options.
  499. pb_backupbuddy::$classes['core']->backup_integrity_check( $file );
  500. // Backup status.
  501. $pretty_status = array(
  502. 'pass' => '<span class="pb_label pb_label-success">Good</span>', //'Good',
  503. 'fail' => '<span class="pb_label pb_label-important">Bad</span>',
  504. );
  505. // Backup type.
  506. $pretty_type = array(
  507. 'full' => 'Full',
  508. 'db' => 'Database',
  509. );
  510. $step_times = array();
  511. if ( isset( pb_backupbuddy::$options['backups'][$serial]['steps'] ) ) {
  512. foreach( pb_backupbuddy::$options['backups'][$serial]['steps'] as $step ) {
  513. if ( isset( $step['finish_time'] ) && ( $step['finish_time'] != 0 ) ) {
  514. // Step time taken.
  515. $step_times[] = $step['finish_time'] - $step['start_time'];
  516. }
  517. } // End foreach.
  518. } else { // End if serial in array is set.
  519. $step_times[] = 'unknown';
  520. } // End if serial in array is NOT set.
  521. $step_times = implode( ', ', $step_times );
  522. // Calculate zipping step time to use later for calculating write speed.
  523. if ( isset( pb_backupbuddy::$options['backups'][$serial]['steps']['backup_zip_files'] ) ) {
  524. $zip_time = pb_backupbuddy::$options['backups'][$serial]['steps']['backup_zip_files'];
  525. } else {
  526. $zip_time = 0;
  527. }
  528. // Calculate write speed in MB/sec for this backup.
  529. if ( $zip_time == '0' ) { // Took approx 0 seconds to backup so report this speed.
  530. if ( !isset( $finish_time ) || ( $finish_time == '0' ) ) {
  531. $write_speed = 'unknown';
  532. } else {
  533. $write_speed = '> ' . pb_backupbuddy::$format->file_size( pb_backupbuddy::$options['backups'][$serial]['integrity']['size'] );
  534. }
  535. } else {
  536. $write_speed = pb_backupbuddy::$format->file_size( pb_backupbuddy::$options['backups'][$serial]['integrity']['size'] / $zip_time );
  537. }
  538. // Calculate start and finish.
  539. if ( isset( pb_backupbuddy::$options['backups'][$serial]['start_time'] ) && isset( pb_backupbuddy::$options['backups'][$serial]['finish_time'] ) && ( pb_backupbuddy::$options['backups'][$serial]['start_time'] >0 ) && ( pb_backupbuddy::$options['backups'][$serial]['finish_time'] > 0 ) ) {
  540. $start_time = pb_backupbuddy::$options['backups'][$serial]['start_time'];
  541. $finish_time = pb_backupbuddy::$options['backups'][$serial]['finish_time'];
  542. $total_time = $finish_time - $start_time;
  543. } else {
  544. $total_time = 'unknown';
  545. }
  546. // Figure out trigger.
  547. if ( isset( pb_backupbuddy::$options['backups'][$serial]['trigger'] ) ) {
  548. $trigger = pb_backupbuddy::$options['backups'][$serial]['trigger'];
  549. } else {
  550. $trigger = __( 'Unknown', 'it-l10n-backupbuddy' );
  551. }
  552. // HTML output for stats.
  553. $statistics = '';
  554. if ( $total_time != 'unknown' ) {
  555. $statistics .= "<span style='width: 80px; display: inline-block;'>Total time:</span>{$total_time} secs<br>";
  556. }
  557. if ( $step_times != 'unknown' ) {
  558. $statistics .= "<span style='width: 80px; display: inline-block;'>Step times:</span>{$step_times}<br>";
  559. }
  560. if ( $write_speed != 'unknown' ) {
  561. $statistics .= "<span style='width: 80px; display: inline-block;'>Write speed:</span>{$write_speed}/sec";
  562. }
  563. // Calculate time ago.
  564. $time_ago = '<span class="description">' . pb_backupbuddy::$format->time_ago( pb_backupbuddy::$options['backups'][$serial]['integrity']['modified'] ) . ' ago</span>';
  565. // Calculate main row string.
  566. if ( $type == 'default' ) { // Default backup listing.
  567. $main_string = '<a href="' . pb_backupbuddy::ajax_url( 'download_archive' ) . '&backupbuddy_backup=' . basename( $file ) . '">' . basename( $file ) . '</a>';
  568. } elseif ( $type == 'migrate' ) { // Migration backup listing.
  569. $main_string = '<a class="pb_backupbuddy_hoveraction_migrate" rel="' . basename( $file ) . '" href="' . pb_backupbuddy::page_url() . '&migrate=' . basename( $file ) . '&value=' . basename( $file ) . '">' . basename( $file ) . '</a>';
  570. } else {
  571. $main_string = '{Unknown type.}';
  572. }
  573. // Add comment to main row string if applicable.
  574. if ( isset( pb_backupbuddy::$options['backups'][$serial]['integrity']['comment'] ) && ( pb_backupbuddy::$options['backups'][$serial]['integrity']['comment'] !== false ) && ( pb_backupbuddy::$options['backups'][$serial]['integrity']['comment'] !== '' ) ) {
  575. $main_string .= '<br><span class="description">Note: <span class="pb_backupbuddy_notetext">' . pb_backupbuddy::$options['backups'][$serial]['integrity']['comment'] . '</span></span>';
  576. }
  577. if ( pb_backupbuddy::$options['backups'][$serial]['integrity']['status'] == 'pass' ) {
  578. $status_details = __( 'All tests passed.', 'it-l10n-backupbuddy' );
  579. } else {
  580. $status_details = pb_backupbuddy::$options['backups'][$serial]['integrity']['status_details'];
  581. }
  582. $backups[basename( $file )] = array(
  583. array( basename( $file ), $main_string ),
  584. pb_backupbuddy::$format->prettify( pb_backupbuddy::$options['backups'][$serial]['integrity']['detected_type'], $pretty_type ),
  585. pb_backupbuddy::$format->file_size( pb_backupbuddy::$options['backups'][$serial]['integrity']['size'] ),
  586. pb_backupbuddy::$format->date( pb_backupbuddy::$format->localize_time( pb_backupbuddy::$options['backups'][$serial]['integrity']['modified'] ) ) . '<br>' . $time_ago,
  587. $statistics,
  588. pb_backupbuddy::$format->prettify( pb_backupbuddy::$options['backups'][$serial]['integrity']['status'], $pretty_status ) .
  589. ' <a href="' . pb_backupbuddy::page_url() . '&reset_integrity=' . $serial . '" title="Rescan integrity. Last checked ' . pb_backupbuddy::$format->date( pb_backupbuddy::$options['backups'][$serial]['integrity']['scan_time'] ) . '."><img src="' . pb_backupbuddy::plugin_url() . '/images/refresh_gray.gif" style="vertical-align: -1px;"></a>' .
  590. '<div class="row-actions"><a title="' . __( 'Integrity Check Details', 'it-l10n-backupbuddy' ) . '" href="' . pb_backupbuddy::ajax_url( 'integrity_status' ) . '&serial=' . $serial . '&#038;TB_iframe=1&#038;width=640&#038;height=600" class="thickbox">' . __( 'View Details', 'it-l10n-backupbuddy' ) . '</a></div>',
  591. );
  592. $backup_sort_dates[basename( $file)] = pb_backupbuddy::$options['backups'][$serial]['integrity']['modified'];
  593. } // End foreach().
  594. } // End if.
  595. // Sort backup sizes.
  596. arsort( $backup_sort_dates );
  597. // Re-arrange backups based on sort dates.
  598. $sorted_backups = array();
  599. foreach( $backup_sort_dates as $backup_file => $backup_sort_date ) {
  600. $sorted_backups[$backup_file] = $backups[$backup_file];
  601. unset( $backups[$backup_file] );
  602. }
  603. unset( $backups );
  604. return $sorted_backups;
  605. } // End backups_list().
  606. // If output file not specified then outputs to browser as download.
  607. // IMPORTANT: If outputting to browser (no output file) must die() after outputting content if using AJAX. Do not output to browser anything after this function in this case.
  608. public static function importbuddy( $output_file = '', $importbuddy_pass_hash = '' ) {
  609. if ( defined( 'PB_DEMO_MODE' ) ) {
  610. echo 'Access denied in demo mode.';
  611. return;
  612. }
  613. pb_backupbuddy::set_greedy_script_limits(); // Some people run out of PHP memory.
  614. if ( $importbuddy_pass_hash == '' ) {
  615. if ( !isset( pb_backupbuddy::$options ) ) {
  616. pb_backupbuddy::load();
  617. }
  618. $importbuddy_pass_hash = pb_backupbuddy::$options['importbuddy_pass_hash'];
  619. }
  620. if ( $importbuddy_pass_hash == '' ) {
  621. $message = 'Error #9032: Warning only - You have not set a password to generate the ImportBuddy script yet on the BackupBuddy Settings page. If you are creating a backup, the importbuddy.php restore script will not be included in the backup. You can download it from the Restore page. If you were trying to download ImportBuddy then you may have a plugin confict preventing the page from prompting you to enter a password.';
  622. pb_backupbuddy::status( 'warning', $message );
  623. return false;
  624. }
  625. $output = file_get_contents( pb_backupbuddy::plugin_path() . '/_importbuddy/_importbuddy.php' );
  626. if ( $importbuddy_pass_hash != '' ) {
  627. $output = preg_replace('/#PASSWORD#/', $importbuddy_pass_hash, $output, 1 ); // Only replaces first instance.
  628. }
  629. $output = preg_replace('/#VERSION#/', pb_backupbuddy::settings( 'version' ), $output, 1 ); // Only replaces first instance.
  630. // PACK IMPORTBUDDY
  631. $_packdata = array( // NO TRAILING OR PRECEEDING SLASHES!
  632. '_importbuddy/importbuddy' => 'importbuddy',
  633. 'classes/_migrate_database.php' => 'importbuddy/classes/_migrate_database.php',
  634. 'classes/core.php' => 'importbuddy/classes/core.php',
  635. 'classes/import.php' => 'importbuddy/classes/import.php',
  636. 'images/working.gif' => 'importbuddy/images/working.gif',
  637. 'images/bullet_go.png' => 'importbuddy/images/bullet_go.png',
  638. 'images/favicon.png' => 'importbuddy/images/favicon.png',
  639. 'images/sort_down.png' => 'importbuddy/images/sort_down.png',
  640. 'lib/dbreplace' => 'importbuddy/lib/dbreplace',
  641. 'lib/dbimport' => 'importbuddy/lib/dbimport',
  642. 'lib/commandbuddy' => 'importbuddy/lib/commandbuddy',
  643. 'lib/zipbuddy' => 'importbuddy/lib/zipbuddy',
  644. 'lib/mysqlbuddy' => 'importbuddy/lib/mysqlbuddy',
  645. 'lib/textreplacebuddy' => 'importbuddy/lib/textreplacebuddy',
  646. 'lib/cpanel' => 'importbuddy/lib/cpanel',
  647. 'pluginbuddy' => 'importbuddy/pluginbuddy',
  648. 'controllers/pages/server_info' => 'importbuddy/controllers/pages/server_info',
  649. 'controllers/pages/server_info.php' => 'importbuddy/controllers/pages/server_info.php',
  650. //'classes/_get_backup_dat.php' => 'importbuddy/classes/_get_backup_dat.php',
  651. // Stash
  652. 'destinations/stash/lib/class.itx_helper.php' => 'importbuddy/classes/class.itx_helper.php',
  653. 'destinations/stash/lib/aws-sdk/lib/requestcore' => 'importbuddy/lib/requestcore',
  654. //'destinations/bootstrap.php' => 'importbuddy/destinations/bootstrap.php',
  655. //'destinations/stash' => 'importbuddy/destinations/stash',
  656. );
  657. $output .= "\n<?php /*\n###PACKDATA,BEGIN\n";
  658. foreach( $_packdata as $pack_source => $pack_destination ) {
  659. $pack_source = '/' . $pack_source;
  660. if ( is_dir( pb_backupbuddy::plugin_path() . $pack_source ) ) {
  661. $files = pb_backupbuddy::$filesystem->deepglob( pb_backupbuddy::plugin_path() . $pack_source );
  662. } else {
  663. $files = array( pb_backupbuddy::plugin_path() . $pack_source );
  664. }
  665. foreach( $files as $file ) {
  666. if ( is_file( $file ) ) {
  667. $source = str_replace( pb_backupbuddy::plugin_path(), '', $file );
  668. $destination = $pack_destination . substr( $source, strlen( $pack_source ) );
  669. $output .= "###PACKDATA,FILE_START,{$source},{$destination}\n";
  670. $output .= base64_encode( file_get_contents( $file ) );
  671. $output .= "\n";
  672. $output .= "###PACKDATA,FILE_END,{$source},{$destination}\n";
  673. }
  674. }
  675. }
  676. $output .= "###PACKDATA,END\n*/";
  677. $output .= "\n\n\n\n\n\n\n\n\n\n";
  678. if ( $output_file == '' ) { // No file so output to browser.
  679. header( 'Content-Description: File Transfer' );
  680. header( 'Content-Type: text/plain; name=importbuddy.php' );
  681. header( 'Content-Disposition: attachment; filename=importbuddy.php' );
  682. header( 'Expires: 0' );
  683. header( 'Content-Length: ' . strlen( $output ) );
  684. flush();
  685. echo $output;
  686. flush();
  687. // BE SURE TO die() AFTER THIS AND NOT OUTPUT TO BROWSER!
  688. } else { // Write to file.
  689. file_put_contents( $output_file, $output );
  690. }
  691. } // End importbuddy().
  692. // TODO: RepairBuddy is not yet converted into new framework so just using pre-BB3.0 version for now.
  693. public function repairbuddy( $output_file = '' ) {
  694. if ( defined( 'PB_DEMO_MODE' ) ) {
  695. echo 'Access denied in demo mode.';
  696. return;
  697. }
  698. if ( !isset( pb_backupbuddy::$options ) ) {
  699. pb_backupbuddy::load();
  700. }
  701. $output = file_get_contents( pb_backupbuddy::plugin_path() . '/_repairbuddy.php' );
  702. if ( pb_backupbuddy::$options['repairbuddy_pass_hash'] != '' ) {
  703. $output = preg_replace('/#PASSWORD#/', pb_backupbuddy::$options['repairbuddy_pass_hash'], $output, 1 ); // Only replaces first instance.
  704. }
  705. $output = preg_replace('/#VERSION#/', pb_backupbuddy::settings( 'version' ), $output, 1 ); // Only replaces first instance.
  706. if ( $output_file == '' ) { // No file so output to browser.
  707. header( 'Content-Description: File Transfer' );
  708. header( 'Content-Type: text/plain; name=repairbuddy.php' );
  709. header( 'Content-Disposition: attachment; filename=repairbuddy.php' );
  710. header( 'Expires: 0' );
  711. header( 'Content-Length: ' . strlen( $output ) );
  712. flush();
  713. echo $output;
  714. flush();
  715. // BE SURE TO die() AFTER THIS AND NOT OUTPUT TO BROWSER!
  716. } else { // Write to file.
  717. file_put_contents( $output_file, $output );
  718. }
  719. } // End repairbuddy().
  720. function pretty_destination_type( $type ) {
  721. if ( $type == 'rackspace' ) {
  722. return 'Rackspace';
  723. } elseif ( $type == 'email' ) {
  724. return 'Email';
  725. } elseif ( $type == 's3' ) {
  726. return 'Amazon S3';
  727. } elseif ( $type == 'ftp' ) {
  728. return 'FTP';
  729. } elseif ( $type == 'dropbox' ) {
  730. return 'Dropbox';
  731. } else {
  732. return $type;
  733. }
  734. } // End pretty_destination_type().
  735. // $max_depth int Maximum depth of tree to display. Npte that deeper depths are still traversed for size calculations.
  736. function build_icicle( $dir, $base, $icicle_json, $max_depth = 10, $depth_count = 0, $is_root = true ) {
  737. $bg_color = '005282';
  738. $depth_count++;
  739. $bg_color = dechex( hexdec( $bg_color ) - ( $depth_count * 15 ) );
  740. $icicle_json = '{' . "\n";
  741. $dir_name = $dir;
  742. $dir_name = str_replace( ABSPATH, '', $dir );
  743. $dir_name = str_replace( '\\', '/', $dir_name );
  744. $dir_size = 0;
  745. $sub = opendir( $dir );
  746. $has_children = false;
  747. while( $file = readdir( $sub ) ) {
  748. if ( ( $file == '.' ) || ( $file == '..' ) ) {
  749. continue; // Next loop.
  750. } elseif ( is_dir( $dir . '/' . $file ) ) {
  751. $dir_array = '';
  752. $response = $this->build_icicle( $dir . '/' . $file, $base, $dir_array, $max_depth, $depth_count, false );
  753. if ( ( $max_depth-1 > 0 ) || ( $max_depth == -1 ) ) { // Only adds to the visual tree if depth isnt exceeded.
  754. if ( $max_depth > 0 ) {
  755. $max_depth = $max_depth - 1;
  756. }
  757. if ( $has_children === false ) { // first loop add children section
  758. $icicle_json .= '"children": [' . "\n";
  759. } else {
  760. $icicle_json .= ',';
  761. }
  762. $icicle_json .= $response[0];
  763. $has_children = true;
  764. }
  765. $dir_size += $response[1];
  766. unset( $response );
  767. unset( $file );
  768. } else {
  769. $stats = stat( $dir . '/' . $file );
  770. $dir_size += $stats['size'];
  771. unset( $file );
  772. }
  773. }
  774. closedir( $sub );
  775. unset( $sub );
  776. if ( $has_children === true ) {
  777. $icicle_json .= ' ]' . "\n";
  778. }
  779. if ( $has_children === true ) {
  780. $icicle_json .= ',';
  781. }
  782. $icicle_json .= '"id": "node_' . str_replace( '/', ':', $dir_name ) . ': ^' . str_replace( ' ', '~', pb_backupbuddy::$format->file_size( $dir_size ) ) . '"' . "\n";
  783. $dir_name = str_replace( '/', '', strrchr( $dir_name, '/' ) );
  784. if ( $dir_name == '' ) { // Set root to be /.
  785. $dir_name = '/';
  786. }
  787. $icicle_json .= ', "name": "' . $dir_name . ' (' . pb_backupbuddy::$format->file_size( $dir_size ) . ')"' . "\n";
  788. $icicle_json .= ',"data": { "$dim": ' . ( $dir_size + 10 ) . ', "$color": "#' . str_pad( $bg_color, 6, '0', STR_PAD_LEFT ) . '" }' . "\n";
  789. $icicle_json .= '}';
  790. if ( $is_root !== true ) {
  791. //$icicle_json .= ',x';
  792. }
  793. return array( $icicle_json, $dir_size );
  794. } // End build_icicle().
  795. // return array of tests and their results.
  796. public function preflight_check() {
  797. $tests = array();
  798. // MULTISITE BETA WARNING.
  799. if ( is_multisite() && pb_backupbuddy::$classes['core']->is_network_activated() && !defined( 'PB_DEMO_MODE' ) ) { // Multisite installation.
  800. $tests[] = array(
  801. 'test' => 'multisite_beta',
  802. 'success' => false,
  803. 'message' => 'BETA WARNING:
  804. Multisite functionality is in BETA and is not supported. It is for preview or experimental use only. It is not for use on live sites.
  805. Use of beta Multisite features on production sites is at your own risk.
  806. See the <a href="http://ithemes.com/codex/page/BackupBuddy_Multisite">Multisite Knowledge Base</a> for additional information.
  807. Multisite functionality does not receive official technical support due to the beta status.
  808. <br><br>
  809. Migrating entire Multisite Networks to a new URL is NOT supported.
  810. Networks cannot not be migrated to a new URL (especially in or out of a subdirectory) without advanced user assistance.
  811. As such, we do not officially support migrating a Network to a new URL.
  812. If you do migrate an entire Network to a new URL only the main site URLs will be migrated in the
  813. database. You may use the Server Information page Mass Database Text Replacement tool to manually
  814. migrate each subsite URL as needed. We recommend only advanced users attempt this. This is a technical
  815. limitation of Multisite Network migrations only, and only when the URL would change.
  816. '
  817. );
  818. }
  819. // LOOPBACKS TEST.
  820. if ( ( $loopback_response = $this->loopback_test() ) === true ) {
  821. $success = true;
  822. $message = '';
  823. } else { // failed
  824. $success = false;
  825. if ( defined( 'ALTERNATE_WP_CRON' ) && ( ALTERNATE_WP_CRON == true ) ) {
  826. $message = __('Running in Alternate WordPress Cron mode. HTTP Loopback Connections are not enabled on this server but you have overridden this in the wp-config.php file (this is a good thing).', 'it-l10n-backupbuddy' ) . ' <a href="http://ithemes.com/codex/page/BackupBuddy:_Frequent_Support_Issues#HTTP_Loopback_Connections_Disabled" target="_new">' . __('Additional Information Here', 'it-l10n-backupbuddy' ) . '</a>.';
  827. } else {
  828. $message = __('HTTP Loopback Connections are not enabled on this server. You may encounter stalled, significantly delayed backups, or other difficulties.', 'it-l10n-backupbuddy' ) . ' <a href="http://ithemes.com/codex/page/BackupBuddy:_Frequent_Support_Issues#HTTP_Loopback_Connections_Disabled" target="_new">' . __('Click for instructions on how to resolve this issue.', 'it-l10n-backupbuddy' ) . '</a>';
  829. }
  830. }
  831. $tests[] = array(
  832. 'test' => 'loopbacks',
  833. 'success' => $success,
  834. 'message' => $message,
  835. );
  836. // Reminder if no schedules are set up yet.
  837. /* CURRENTLY MOVED TO SCHEDULES PAGE.
  838. if ( count( pb_backupbuddy::$options['schedules'] ) == 0 ) {
  839. $success = false;
  840. $message = __( 'Reminder: Creating a <a href="?page=pb_backupbuddy_scheduling">scheduled backup</a> keeps your site safe and backed up without requiring manual backups. Create a schedule or dismiss this alert (link to the right) to hide it.', 'it-l10n-backupbuddy' );
  841. } else {
  842. $success = true;
  843. $message = '';
  844. }
  845. $tests[] = array(
  846. 'test' => 'no_schedule_reminder',
  847. 'success' => $success,
  848. 'message' => $message,
  849. );
  850. */
  851. // WORDPRESS IN SUBDIRECTORIES TEST.
  852. $wordpress_locations = $this->get_wordpress_locations();
  853. if ( count( $wordpress_locations ) > 0 ) {
  854. $success = false;
  855. $message = __( 'WordPress may have been detected in one or more subdirectories. Backing up multiple instances of WordPress may result in server timeouts due to increased backup time. You may exclude WordPress directories via the Settings page. Detected non-excluded locations:', 'it-l10n-backupbuddy' ) . ' ' . implode( ', ', $wordpress_locations );
  856. } else {
  857. $success = true;
  858. $message = '';
  859. }
  860. $tests[] = array(
  861. 'test' => 'wordpress_subdirectories',
  862. 'success' => $success,
  863. 'message' => $message,
  864. );
  865. // Log file directory writable for status logging.
  866. $status_directory = WP_CONTENT_DIR . '/uploads/pb_' . pb_backupbuddy::settings( 'slug' ) . '/';
  867. if ( ! is_writable( $status_directory ) ) {
  868. $success = false;
  869. $message = 'The status log file directory `' . $status_directory . '` is not writable. Please verify permissions before creating a backup. Backup status information will be unavailable until this is resolved.';
  870. } else {
  871. $success = true;
  872. $message = '';
  873. }
  874. $tests[] = array(
  875. 'test' => 'status_directory_writable',
  876. 'success' => $success,
  877. 'message' => $message,
  878. );
  879. // CHECK ZIP AVAILABILITY.
  880. require_once( pb_backupbuddy::plugin_path() . '/lib/zipbuddy/zipbuddy.php' );
  881. if ( !isset( pb_backupbuddy::$classes['zipbuddy'] ) ) {
  882. pb_backupbuddy::$classes['zipbuddy'] = new pluginbuddy_zipbuddy( pb_backupbuddy::$options['backup_directory'] );
  883. }
  884. if ( !in_array( 'exec', pb_backupbuddy::$classes['zipbuddy']->_zip_methods ) ) {
  885. $success = false;
  886. $message = __('Your server does not support command line ZIP which is a BackupBuddy server requirement. Backups will be performed in compatibility mode.', 'it-l10n-backupbuddy' )
  887. . __('Directory/file exclusion is not available in this mode so even existing backups will be backed up.', 'it-l10n-backupbuddy' )
  888. . ' '
  889. . __('You may encounter stalled or significantly delayed backups.', 'it-l10n-backupbuddy' )
  890. . '<a href="http://ithemes.com/codex/page/BackupBuddy:_Frequent_Support_Issues#Compatibility_Mode" target="_new">'
  891. . ' ' . __('Click for instructions on how to resolve this issue.', 'it-l10n-backupbuddy' )
  892. . '</a>';
  893. } else { // Success.
  894. $success = true;
  895. $message = '';
  896. }
  897. $tests[] = array(
  898. 'test' => 'zip_methods',
  899. 'success' => $success,
  900. 'message' => $message,
  901. );
  902. // Show warning if recent backups reports it is not complete yet. (3min is recent)
  903. if ( isset( pb_backupbuddy::$options['backups'][pb_backupbuddy::$options['last_backup_serial']]['updated_time'] ) && ( time() - pb_backupbuddy::$options['backups'][pb_backupbuddy::$options['last_backup_serial']]['updated_time'] < 180 ) ) { // Been less than 3min since last backup.
  904. if ( !empty( pb_backupbuddy::$options['backups'][pb_backupbuddy::$options['last_backup_serial']]['steps'] ) ) {
  905. $found_unfinished = false;
  906. foreach( pb_backupbuddy::$options['backups'][pb_backupbuddy::$options['last_backup_serial']]['steps'] as $step ) {
  907. if ( $step['finish_time'] == '0' ) { // Found an unfinished step.
  908. $found_unfinished = true;
  909. break;
  910. }
  911. }
  912. if ( $found_unfinished === true ) {
  913. $tests[] = array(
  914. 'test' => 'recent_backup',
  915. 'success' => false,
  916. 'message' => __('A backup was recently started and reports unfinished steps. You should wait unless you are sure the previous backup has completed or failed to avoid placing a heavy load on your server.', 'it-l10n-backupbuddy' ) .
  917. ' Last updated: ' . pb_backupbuddy::$format->date( pb_backupbuddy::$options['backups'][pb_backupbuddy::$options['last_backup_serial']]['updated_time'] ) . '; '.
  918. ' Serial: ' . pb_backupbuddy::$options['last_backup_serial']
  919. ,
  920. );
  921. }
  922. }
  923. }
  924. // Check if any backups are in site root (ie from a recent …

Large files files are truncated, but you can click here to view the full file