PageRenderTime 35ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 1ms

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

https://bitbucket.org/summitds/bloomsburgpa.org
PHP | 1988 lines | 1373 code | 318 blank | 297 comment | 246 complexity | b08e737a3a43b1207f915dacf2b7d0f7 MD5 | raw file
Possible License(s): GPL-2.0, AGPL-1.0, BSD-3-Clause, GPL-3.0, LGPL-2.1
  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. * @param bool $trim_suffix True (default) if trailing slash should be trimmed from directories
  226. * @return array Array of directories to exclude.
  227. */
  228. public static function get_directory_exclusions( $trim_suffix = true ) {
  229. // Get initial array.
  230. $exclusions = trim( pb_backupbuddy::$options['excludes'] ); // Trim string.
  231. $exclusions = preg_split('/\n|\r|\r\n/', $exclusions ); // Break into array on any type of line ending.
  232. $abspath = str_replace( '\\', '/', ABSPATH );
  233. // Add additional internal exclusions.
  234. $exclusions[] = str_replace( rtrim( $abspath, '\\\/' ), '', pb_backupbuddy::$options['backup_directory'] ); // Exclude backup directory.
  235. $exclusions[] = '/wp-content/uploads/pb_backupbuddy/'; // BackupBuddy logs and junk.
  236. $exclusions[] = '/importbuddy/'; // Exclude importbuddy directory in root.
  237. $exclusions[] = '/importbuddy.php'; // Exclude importbuddy.php script in root.
  238. // Clean up & sanitize array.
  239. if ( $trim_suffix ) {
  240. array_walk( $exclusions, create_function( '&$val', '$val = rtrim( trim( $val ), \'/\' );' ) ); // Apply trim to all items within.
  241. } else {
  242. array_walk( $exclusions, create_function( '&$val', '$val = trim( $val );' ) ); // Apply (whitespace-only) trim to all items within.
  243. }
  244. $exclusions = array_filter( $exclusions, 'strlen' ); // Remove any empty / blank lines.
  245. // IMPORTANT NOTE: Cannot exclude the temp directory here as this is where SQL and DAT files are stored for inclusion in the backup archive.
  246. return $exclusions;
  247. } // End get_directory_exclusions().
  248. /* mail_error()
  249. *
  250. * Sends an error email to the defined email address(es) on settings page.
  251. *
  252. * @param string $message Message to be included in the body of the email.
  253. * @return null
  254. */
  255. function mail_error( $message ) {
  256. if ( !isset( pb_backupbuddy::$options ) ) {
  257. pb_backupbuddy::load();
  258. }
  259. $subject = pb_backupbuddy::$options['email_notify_error_subject'];
  260. $body = pb_backupbuddy::$options['email_notify_error_body'];
  261. $replacements = array(
  262. '{site_url}' => site_url(),
  263. '{backupbuddy_version}' => pb_backupbuddy::settings( 'version' ),
  264. '{current_datetime}' => date(DATE_RFC822),
  265. '{message}' => $message
  266. );
  267. foreach( $replacements as $replace_key => $replacement ) {
  268. $subject = str_replace( $replace_key, $replacement, $subject );
  269. $body = str_replace( $replace_key, $replacement, $body );
  270. }
  271. $email = pb_backupbuddy::$options['email_notify_error'];
  272. pb_backupbuddy::status( 'error', 'Sending email error notification. Subject: `' . $subject . '`; body: `' . $body . '`; recipient(s): `' . $email . '`.' );
  273. if ( !empty( $email ) ) {
  274. wp_mail( $email, $subject, $body, 'From: '.$email."\r\n".'Reply-To: '.get_option('admin_email')."\r\n");
  275. }
  276. } // End mail_error().
  277. /* mail_notify_scheduled()
  278. *
  279. * Sends a message email to the defined email address(es) on settings page.
  280. *
  281. * @param string $start_or_complete Whether this is the notifcation for starting or completing. Valid values: start, complete
  282. * @param string $message Message to be included in the body of the email.
  283. * @return null
  284. */
  285. function mail_notify_scheduled( $serial, $start_or_complete, $message ) {
  286. if ( !isset( pb_backupbuddy::$options ) ) {
  287. pb_backupbuddy::load();
  288. }
  289. if ( $start_or_complete == 'start' ) {
  290. $email = pb_backupbuddy::$options['email_notify_scheduled_start'];
  291. $subject = pb_backupbuddy::$options['email_notify_scheduled_start_subject'];
  292. $body = pb_backupbuddy::$options['email_notify_scheduled_start_body'];
  293. $replacements = array(
  294. '{site_url}' => site_url(),
  295. '{backupbuddy_version}' => pb_backupbuddy::settings( 'version' ),
  296. '{current_datetime}' => date(DATE_RFC822),
  297. '{message}' => $message
  298. );
  299. } elseif ( $start_or_complete == 'complete' ) {
  300. $email = pb_backupbuddy::$options['email_notify_scheduled_complete'];
  301. $subject = pb_backupbuddy::$options['email_notify_scheduled_complete_subject'];
  302. $body = pb_backupbuddy::$options['email_notify_scheduled_complete_body'];
  303. $replacements = array(
  304. '{site_url}' => site_url(),
  305. '{backupbuddy_version}' => pb_backupbuddy::settings( 'version' ),
  306. '{current_datetime}' => date(DATE_RFC822),
  307. '{message}' => $message,
  308. '{backup_serial}' => $serial,
  309. '{download_link}' => pb_backupbuddy::ajax_url( 'download_archive' ) . '&backupbuddy_backup=' . basename( pb_backupbuddy::$options['backups'][$serial]['archive_file'] ),
  310. '{backup_file}' => basename( pb_backupbuddy::$options['backups'][$serial]['archive_file'] ),
  311. '{backup_size}' => pb_backupbuddy::$format->file_size( pb_backupbuddy::$options['backups'][$serial]['archive_size'] ),
  312. '{backup_type}' => pb_backupbuddy::$options['backups'][$serial]['type'],
  313. );
  314. } else {
  315. pb_backupbuddy::status( 'error', 'ERROR #54857845785: Fatally halted. Invalid schedule type. Expected `start` or `complete`. Got `' . $start_or_complete . '`.' );
  316. }
  317. foreach( $replacements as $replace_key => $replacement ) {
  318. $subject = str_replace( $replace_key, $replacement, $subject );
  319. $body = str_replace( $replace_key, $replacement, $body );
  320. }
  321. pb_backupbuddy::status( 'error', 'Sending email schedule notification. Subject: `' . $subject . '`; body: `' . $body . '`; recipient(s): `' . $email . '`.' );
  322. if ( !empty( $email ) ) {
  323. wp_mail( $email, $subject, $body, 'From: '.$email."\r\n".'Reply-To: '.get_option('admin_email')."\r\n");
  324. }
  325. } // End mail_notify_scheduled().
  326. /* backup_prefix()
  327. *
  328. * Strips all non-file-friendly characters from the site URL. Used in making backup zip filename.
  329. *
  330. * @return string The filename friendly converted site URL.
  331. */
  332. function backup_prefix() {
  333. $siteurl = site_url();
  334. $siteurl = str_replace( 'http://', '', $siteurl );
  335. $siteurl = str_replace( 'https://', '', $siteurl );
  336. $siteurl = str_replace( '/', '_', $siteurl );
  337. $siteurl = str_replace( '\\', '_', $siteurl );
  338. $siteurl = str_replace( '.', '_', $siteurl );
  339. $siteurl = str_replace( ':', '_', $siteurl ); // Alternative port from 80 is stored in the site url.
  340. $siteurl = str_replace( '~', '_', $siteurl ); // Strip ~.
  341. return $siteurl;
  342. } // End backup_prefix().
  343. /* send_remote_destination()
  344. *
  345. * function description
  346. *
  347. * @param int $destination_id ID number (index of the destinations array) to send it.
  348. * @param string $file Full file path of file to send.
  349. * @param string $trigger What triggered this backup. Valid values: scheduled, manual.
  350. * @param bool $send_importbuddy Whether or not importbuddy.php should also be sent with the file to destination.
  351. * @return bool Send status. true success, false failed.
  352. */
  353. function send_remote_destination( $destination_id, $file, $trigger = '', $send_importbuddy = false ) {
  354. pb_backupbuddy::status( 'details', 'Sending file `' . $file . '` to remote destination `' . $destination_id . '` triggered by `' . $trigger . '`.' );
  355. if ( defined( 'PB_DEMO_MODE' ) ) {
  356. return false;
  357. }
  358. if ( $file == '' ) {
  359. $backup_file_size = filesize( $file );
  360. } else {
  361. $backup_file_size = 50000; // not sure why anything current would be sending importbuddy but NOT sending a backup but just in case...
  362. }
  363. // Record some statistics.
  364. $identifier = pb_backupbuddy::random_string( 12 );
  365. pb_backupbuddy::$options['remote_sends'][$identifier] = array(
  366. 'destination' => $destination_id,
  367. 'file' => $file,
  368. 'file_size' => $backup_file_size,
  369. 'trigger' => $trigger, // What triggered this backup. Valid values: scheduled, manual.
  370. 'send_importbuddy' => $send_importbuddy,
  371. 'start_time' => time(),
  372. 'finish_time' => 0,
  373. 'status' => 'timeout', // success, failure, timeout (default assumption if this is not updated in this PHP load)
  374. );
  375. pb_backupbuddy::save();
  376. // Prepare variables to pass to remote destination handler.
  377. if ( '' == $file ) { // No file to send (blank string file typically happens when just sending importbuddy).
  378. $files = array();
  379. } else {
  380. $files = array( $file );
  381. }
  382. $destination_settings = &pb_backupbuddy::$options['remote_destinations'][$destination_id];
  383. // For Stash we will check the quota prior to initiating send.
  384. if ( pb_backupbuddy::$options['remote_destinations'][$destination_id]['type'] == 'stash' ) {
  385. // Pass off to destination handler.
  386. require_once( pb_backupbuddy::plugin_path() . '/destinations/bootstrap.php' );
  387. $send_result = pb_backupbuddy_destinations::get_info( 'stash' ); // Used to kick the Stash destination into life.
  388. $stash_quota = pb_backupbuddy_destination_stash::get_quota( pb_backupbuddy::$options['remote_destinations'][$destination_id], true );
  389. if ( $file != '' ) {
  390. $backup_file_size = filesize( $file );
  391. } else {
  392. $backip_file_size = 50000;
  393. }
  394. if ( ( $backup_file_size + $stash_quota['quota_used'] ) > $stash_quota['quota_total'] ) {
  395. $message = '';
  396. $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";
  397. $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. ';
  398. $message .= 'Currently using ' . $stash_quota['quota_used_nice'] . ' of ' . $stash_quota['quota_total_nice'] . ' (' . $stash_quota['quota_used_percent'] . '%).';
  399. pb_backupbuddy::status( 'error', $message );
  400. pb_backupbuddy::$classes['core']->mail_error( $message );
  401. pb_backupbuddy::$options['remote_sends'][$identifier]['status'] = 'Failure. Insufficient destination space.';
  402. pb_backupbuddy::save();
  403. return false;
  404. } else {
  405. if ( isset( $stash_quota['quota_warning'] ) && ( $stash_quota['quota_warning'] != '' ) ) {
  406. // We log warning of usage but dont send error email.
  407. $message = '';
  408. $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";
  409. $message .= 'Currently using ' . $stash_quota['quota_used_nice'] . ' of ' . $stash_quota['quota_total_nice'] . ' (' . $stash_quota['quota_used_percent'] . '%).';
  410. pb_backupbuddy::status( 'details', $message );
  411. //pb_backupbuddy::$classes['core']->mail_error( $message );
  412. }
  413. }
  414. }
  415. if ( $send_importbuddy === true ) {
  416. pb_backupbuddy::status( 'details', 'Generating temporary importbuddy.php file for remote send.' );
  417. $importbuddy_temp = pb_backupbuddy::$options['temp_directory'] . 'importbuddy.php'; // Full path & filename to temporary importbuddy
  418. $this->importbuddy( $importbuddy_temp ); // Create temporary importbuddy.
  419. pb_backupbuddy::status( 'details', 'Generated temporary importbuddy.' );
  420. $files[] = $importbuddy_temp; // Add importbuddy file to the list of files to send.
  421. $send_importbuddy = true; // Track to delete after finished.
  422. } else {
  423. pb_backupbuddy::status( 'details', 'Not sending importbuddy.' );
  424. }
  425. // Pass off to destination handler.
  426. require_once( pb_backupbuddy::plugin_path() . '/destinations/bootstrap.php' );
  427. $send_result = pb_backupbuddy_destinations::send( $destination_settings, $files );
  428. $this->kick_db(); // Kick the database to make sure it didn't go away, preventing options saving.
  429. // Update stats.
  430. pb_backupbuddy::$options['remote_sends'][$identifier]['finish_time'] = time();
  431. if ( $send_result === true ) { // succeeded.
  432. pb_backupbuddy::$options['remote_sends'][$identifier]['status'] = 'success';
  433. pb_backupbuddy::status( 'details', 'Remote send SUCCESS.' );
  434. } elseif ( $send_result === false ) { // failed.
  435. pb_backupbuddy::$options['remote_sends'][$identifier]['status'] = 'failure';
  436. pb_backupbuddy::status( 'details', 'Remote send FAILURE.' );
  437. } elseif ( is_array( $send_result ) ) { // Array so multipart.
  438. pb_backupbuddy::$options['remote_sends'][$identifier]['status'] = 'multipart';
  439. pb_backupbuddy::$options['remote_sends'][$identifier]['finish_time'] = 0;
  440. pb_backupbuddy::$options['remote_sends'][$identifier]['_multipart_id'] = $send_result[0];
  441. pb_backupbuddy::$options['remote_sends'][$identifier]['_multipart_status'] = $send_result[1];
  442. pb_backupbuddy::status( 'details', 'Multipart send in progress.' );
  443. } else {
  444. pb_backupbuddy::status( 'error', 'Error #5485785576463. Invalid status send result: `' . $send_result . '`.' );
  445. }
  446. pb_backupbuddy::save();
  447. // If we sent importbuddy then delete the local copy to clean up.
  448. if ( $send_importbuddy !== false ) {
  449. @unlink( $importbuddy_temp ); // Delete temporary importbuddy.
  450. }
  451. return $send_result;
  452. } // End send_remote_destination().
  453. /* destination_send()
  454. *
  455. * Send file(s) to a destination. Pass full array of destination settings.
  456. *
  457. * @param array $destination_settings All settings for this destination for this action.
  458. * @param array $files Array of files to send (full path).
  459. * @return bool|array Bool true = success, bool false = fail, array = multipart transfer.
  460. */
  461. public function destination_send( $destination_settings, $files ) {
  462. // Pass off to destination handler.
  463. require_once( pb_backupbuddy::plugin_path() . '/destinations/bootstrap.php' );
  464. $send_result = pb_backupbuddy_destinations::send( $destination_settings, $files );
  465. return $send_result;
  466. } // End destination_send().
  467. /* backups_list()
  468. *
  469. * function description
  470. *
  471. * @param string $type Valid options: default, migrate
  472. * @param boolean $subsite_mode When in subsite mode only backups for that specific subsite will be listed.
  473. * @return
  474. */
  475. public function backups_list( $type = 'default', $subsite_mode = false ) {
  476. if ( pb_backupbuddy::_POST( 'bulk_action' ) == 'delete_backup' ) {
  477. $needs_save = false;
  478. pb_backupbuddy::verify_nonce( pb_backupbuddy::_POST( '_wpnonce' ) ); // Security check to prevent unauthorized deletions by posting from a remote place.
  479. $deleted_files = array();
  480. foreach( pb_backupbuddy::_POST( 'items' ) as $item ) {
  481. if ( file_exists( pb_backupbuddy::$options['backup_directory'] . $item ) ) {
  482. if ( @unlink( pb_backupbuddy::$options['backup_directory'] . $item ) === true ) {
  483. $deleted_files[] = $item;
  484. if ( count( pb_backupbuddy::$options['backups'] ) > 5 ) { // Keep a minimum number of backups in array for stats.
  485. $this_serial = $this->get_serial_from_file( $item );
  486. unset( pb_backupbuddy::$options['backups'][$this_serial] );
  487. $needs_save = true;
  488. }
  489. } else {
  490. pb_backupbuddy::alert( 'Error: Unable to delete backup file `' . $item . '`. Please verify permissions.', true );
  491. }
  492. } // End if file exists.
  493. } // End foreach.
  494. if ( $needs_save === true ) {
  495. pb_backupbuddy::save();
  496. }
  497. pb_backupbuddy::alert( __( 'Deleted backup(s):', 'it-l10n-backupbuddy' ) . ' ' . implode( ', ', $deleted_files ) );
  498. } // End if deleting backup(s).
  499. $backups = array();
  500. $backup_sort_dates = array();
  501. $files = glob( pb_backupbuddy::$options['backup_directory'] . 'backup*.zip' );
  502. 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.
  503. $backup_prefix = $this->backup_prefix(); // Backup prefix for this site. Used for MS checking that this user can see this backup.
  504. foreach( $files as $file_id => $file ) {
  505. 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.
  506. // Only allow viewing of their own backups.
  507. if ( !strstr( $file, $backup_prefix ) ) {
  508. unset( $files[$file_id] ); // Remove this backup from the list. This user does not have access to it.
  509. continue; // Skip processing to next file.
  510. }
  511. }
  512. $serial = pb_backupbuddy::$classes['core']->get_serial_from_file( $file );
  513. // Populate integrity data structure in options.
  514. pb_backupbuddy::$classes['core']->backup_integrity_check( $file );
  515. // Backup status.
  516. $pretty_status = array(
  517. 'pass' => '<span class="pb_label pb_label-success">Good</span>', //'Good',
  518. 'fail' => '<span class="pb_label pb_label-important">Bad</span>',
  519. );
  520. // Backup type.
  521. $pretty_type = array(
  522. 'full' => 'Full',
  523. 'db' => 'Database',
  524. );
  525. $step_times = array();
  526. if ( isset( pb_backupbuddy::$options['backups'][$serial]['steps'] ) ) {
  527. foreach( pb_backupbuddy::$options['backups'][$serial]['steps'] as $step ) {
  528. if ( isset( $step['finish_time'] ) && ( $step['finish_time'] != 0 ) ) {
  529. // Step time taken.
  530. $step_times[] = $step['finish_time'] - $step['start_time'];
  531. }
  532. } // End foreach.
  533. } else { // End if serial in array is set.
  534. $step_times[] = 'unknown';
  535. } // End if serial in array is NOT set.
  536. $step_times = implode( ', ', $step_times );
  537. // Calculate zipping step time to use later for calculating write speed.
  538. if ( isset( pb_backupbuddy::$options['backups'][$serial]['steps']['backup_zip_files'] ) ) {
  539. $zip_time = pb_backupbuddy::$options['backups'][$serial]['steps']['backup_zip_files'];
  540. } else {
  541. $zip_time = 0;
  542. }
  543. // Calculate write speed in MB/sec for this backup.
  544. if ( $zip_time == '0' ) { // Took approx 0 seconds to backup so report this speed.
  545. if ( !isset( $finish_time ) || ( $finish_time == '0' ) ) {
  546. $write_speed = 'unknown';
  547. } else {
  548. $write_speed = '> ' . pb_backupbuddy::$format->file_size( pb_backupbuddy::$options['backups'][$serial]['integrity']['size'] );
  549. }
  550. } else {
  551. $write_speed = pb_backupbuddy::$format->file_size( pb_backupbuddy::$options['backups'][$serial]['integrity']['size'] / $zip_time );
  552. }
  553. // Calculate start and finish.
  554. 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 ) ) {
  555. $start_time = pb_backupbuddy::$options['backups'][$serial]['start_time'];
  556. $finish_time = pb_backupbuddy::$options['backups'][$serial]['finish_time'];
  557. $total_time = $finish_time - $start_time;
  558. } else {
  559. $total_time = 'unknown';
  560. }
  561. // Figure out trigger.
  562. if ( isset( pb_backupbuddy::$options['backups'][$serial]['trigger'] ) ) {
  563. $trigger = pb_backupbuddy::$options['backups'][$serial]['trigger'];
  564. } else {
  565. $trigger = __( 'Unknown', 'it-l10n-backupbuddy' );
  566. }
  567. // HTML output for stats.
  568. $statistics = '';
  569. if ( $total_time != 'unknown' ) {
  570. $statistics .= "<span style='width: 80px; display: inline-block;'>Total time:</span>{$total_time} secs<br>";
  571. }
  572. if ( $step_times != 'unknown' ) {
  573. $statistics .= "<span style='width: 80px; display: inline-block;'>Step times:</span>{$step_times}<br>";
  574. }
  575. if ( $write_speed != 'unknown' ) {
  576. $statistics .= "<span style='width: 80px; display: inline-block;'>Write speed:</span>{$write_speed}/sec";
  577. }
  578. // Calculate time ago.
  579. $time_ago = '<span class="description">' . pb_backupbuddy::$format->time_ago( pb_backupbuddy::$options['backups'][$serial]['integrity']['modified'] ) . ' ago</span>';
  580. // Calculate main row string.
  581. if ( $type == 'default' ) { // Default backup listing.
  582. $main_string = '<a href="' . pb_backupbuddy::ajax_url( 'download_archive' ) . '&backupbuddy_backup=' . basename( $file ) . '">' . basename( $file ) . '</a>';
  583. } elseif ( $type == 'migrate' ) { // Migration backup listing.
  584. $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>';
  585. } else {
  586. $main_string = '{Unknown type.}';
  587. }
  588. // Add comment to main row string if applicable.
  589. if ( isset( pb_backupbuddy::$options['backups'][$serial]['integrity']['comment'] ) && ( pb_backupbuddy::$options['backups'][$serial]['integrity']['comment'] !== false ) && ( pb_backupbuddy::$options['backups'][$serial]['integrity']['comment'] !== '' ) ) {
  590. $main_string .= '<br><span class="description">Note: <span class="pb_backupbuddy_notetext">' . htmlentities( pb_backupbuddy::$options['backups'][$serial]['integrity']['comment'] ) . '</span></span>';
  591. }
  592. if ( pb_backupbuddy::$options['backups'][$serial]['integrity']['status'] == 'pass' ) {
  593. $status_details = __( 'All tests passed.', 'it-l10n-backupbuddy' );
  594. } else {
  595. $status_details = pb_backupbuddy::$options['backups'][$serial]['integrity']['status_details'];
  596. }
  597. $backups[basename( $file )] = array(
  598. array( basename( $file ), $main_string ),
  599. pb_backupbuddy::$format->prettify( pb_backupbuddy::$options['backups'][$serial]['integrity']['detected_type'], $pretty_type ),
  600. pb_backupbuddy::$format->file_size( pb_backupbuddy::$options['backups'][$serial]['integrity']['size'] ),
  601. pb_backupbuddy::$format->date( pb_backupbuddy::$format->localize_time( pb_backupbuddy::$options['backups'][$serial]['integrity']['modified'] ) ) . '<br>' . $time_ago,
  602. $statistics,
  603. pb_backupbuddy::$format->prettify( pb_backupbuddy::$options['backups'][$serial]['integrity']['status'], $pretty_status ) .
  604. ' <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>' .
  605. '<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>',
  606. );
  607. $backup_sort_dates[basename( $file)] = pb_backupbuddy::$options['backups'][$serial]['integrity']['modified'];
  608. } // End foreach().
  609. } // End if.
  610. // Sort backup sizes.
  611. arsort( $backup_sort_dates );
  612. // Re-arrange backups based on sort dates.
  613. $sorted_backups = array();
  614. foreach( $backup_sort_dates as $backup_file => $backup_sort_date ) {
  615. $sorted_backups[$backup_file] = $backups[$backup_file];
  616. unset( $backups[$backup_file] );
  617. }
  618. unset( $backups );
  619. return $sorted_backups;
  620. } // End backups_list().
  621. // If output file not specified then outputs to browser as download.
  622. // 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.
  623. public static function importbuddy( $output_file = '', $importbuddy_pass_hash = '' ) {
  624. if ( defined( 'PB_DEMO_MODE' ) ) {
  625. echo 'Access denied in demo mode.';
  626. return;
  627. }
  628. pb_backupbuddy::set_greedy_script_limits(); // Some people run out of PHP memory.
  629. if ( $importbuddy_pass_hash == '' ) {
  630. if ( !isset( pb_backupbuddy::$options ) ) {
  631. pb_backupbuddy::load();
  632. }
  633. $importbuddy_pass_hash = pb_backupbuddy::$options['importbuddy_pass_hash'];
  634. }
  635. if ( $importbuddy_pass_hash == '' ) {
  636. $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.';
  637. pb_backupbuddy::status( 'warning', $message );
  638. return false;
  639. }
  640. $output = file_get_contents( pb_backupbuddy::plugin_path() . '/_importbuddy/_importbuddy.php' );
  641. if ( $importbuddy_pass_hash != '' ) {
  642. $output = preg_replace('/#PASSWORD#/', $importbuddy_pass_hash, $output, 1 ); // Only replaces first instance.
  643. }
  644. $output = preg_replace('/#VERSION#/', pb_backupbuddy::settings( 'version' ), $output, 1 ); // Only replaces first instance.
  645. // PACK IMPORTBUDDY
  646. $_packdata = array( // NO TRAILING OR PRECEEDING SLASHES!
  647. '_importbuddy/importbuddy' => 'importbuddy',
  648. 'classes/_migrate_database.php' => 'importbuddy/classes/_migrate_database.php',
  649. 'classes/core.php' => 'importbuddy/classes/core.php',
  650. 'classes/import.php' => 'importbuddy/classes/import.php',
  651. 'images/working.gif' => 'importbuddy/images/working.gif',
  652. 'images/bullet_go.png' => 'importbuddy/images/bullet_go.png',
  653. 'images/favicon.png' => 'importbuddy/images/favicon.png',
  654. 'images/sort_down.png' => 'importbuddy/images/sort_down.png',
  655. 'lib/dbreplace' => 'importbuddy/lib/dbreplace',
  656. 'lib/dbimport' => 'importbuddy/lib/dbimport',
  657. 'lib/commandbuddy' => 'importbuddy/lib/commandbuddy',
  658. 'lib/zipbuddy' => 'importbuddy/lib/zipbuddy',
  659. 'lib/mysqlbuddy' => 'importbuddy/lib/mysqlbuddy',
  660. 'lib/textreplacebuddy' => 'importbuddy/lib/textreplacebuddy',
  661. 'lib/cpanel' => 'importbuddy/lib/cpanel',
  662. 'pluginbuddy' => 'importbuddy/pluginbuddy',
  663. 'controllers/pages/server_info' => 'importbuddy/controllers/pages/server_info',
  664. 'controllers/pages/server_info.php' => 'importbuddy/controllers/pages/server_info.php',
  665. // Stash
  666. 'destinations/stash/lib/class.itx_helper.php' => 'importbuddy/classes/class.itx_helper.php',
  667. 'destinations/_s3lib/aws-sdk/lib/requestcore' => 'importbuddy/lib/requestcore',
  668. );
  669. $output .= "\n<?php /*\n###PACKDATA,BEGIN\n";
  670. foreach( $_packdata as $pack_source => $pack_destination ) {
  671. $pack_source = '/' . $pack_source;
  672. if ( is_dir( pb_backupbuddy::plugin_path() . $pack_source ) ) {
  673. $files = pb_backupbuddy::$filesystem->deepglob( pb_backupbuddy::plugin_path() . $pack_source );
  674. } else {
  675. $files = array( pb_backupbuddy::plugin_path() . $pack_source );
  676. }
  677. foreach( $files as $file ) {
  678. if ( is_file( $file ) ) {
  679. $source = str_replace( pb_backupbuddy::plugin_path(), '', $file );
  680. $destination = $pack_destination . substr( $source, strlen( $pack_source ) );
  681. $output .= "###PACKDATA,FILE_START,{$source},{$destination}\n";
  682. $output .= base64_encode( file_get_contents( $file ) );
  683. $output .= "\n";
  684. $output .= "###PACKDATA,FILE_END,{$source},{$destination}\n";
  685. }
  686. }
  687. }
  688. $output .= "###PACKDATA,END\n*/";
  689. $output .= "\n\n\n\n\n\n\n\n\n\n";
  690. if ( $output_file == '' ) { // No file so output to browser.
  691. header( 'Content-Description: File Transfer' );
  692. header( 'Content-Type: text/plain; name=importbuddy.php' );
  693. header( 'Content-Disposition: attachment; filename=importbuddy.php' );
  694. header( 'Expires: 0' );
  695. header( 'Content-Length: ' . strlen( $output ) );
  696. flush();
  697. echo $output;
  698. flush();
  699. // BE SURE TO die() AFTER THIS AND NOT OUTPUT TO BROWSER!
  700. } else { // Write to file.
  701. file_put_contents( $output_file, $output );
  702. }
  703. } // End importbuddy().
  704. // If output file not specified then outputs to browser as download.
  705. // 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.
  706. public static function serverbuddy( $output_file = '', $serverbuddy_pass_hash = '' ) {
  707. if ( defined( 'PB_DEMO_MODE' ) ) {
  708. echo 'Access denied in demo mode.';
  709. return;
  710. }
  711. pb_backupbuddy::set_greedy_script_limits(); // Some people run out of PHP memory.
  712. if ( $serverbuddy_pass_hash == '' ) {
  713. if ( !isset( pb_backupbuddy::$options ) ) {
  714. pb_backupbuddy::load();
  715. }
  716. $serverbuddy_pass_hash = pb_backupbuddy::$options['importbuddy_pass_hash'];
  717. }
  718. if ( $serverbuddy_pass_hash == '' ) {
  719. $message = 'Error #9032c: Warning only - You have not set a password to generate the ServerBuddy script yet on the BackupBuddy Settings page. If you were trying to download ServerBuddy then you may have a plugin confict preventing the page from prompting you to enter a password.';
  720. pb_backupbuddy::status( 'warning', $message );
  721. return false;
  722. }
  723. $output = file_get_contents( pb_backupbuddy::plugin_path() . '/_serverbuddy/_serverbuddy.php' );
  724. if ( $serverbuddy_pass_hash != '' ) {
  725. $output = preg_replace('/#PASSWORD#/', $serverbuddy_pass_hash, $output, 1 ); // Only replaces first instance.
  726. }
  727. $output = preg_replace('/#VERSION#/', pb_backupbuddy::settings( 'version' ), $output, 1 ); // Only replaces first instance.
  728. // PACK SERVERBUDDY
  729. $_packdata = array( // NO TRAILING OR PRECEEDING SLASHES!
  730. '_serverbuddy/serverbuddy' => 'serverbuddy',
  731. 'classes/_migrate_database.php' => 'serverbuddy/classes/_migrate_database.php',
  732. 'classes/core.php' => 'serverbuddy/classes/core.php',
  733. 'images/working.gif' => 'serverbuddy/images/working.gif',
  734. 'images/bullet_go.png' => 'serverbuddy/images/bullet_go.png',
  735. 'images/favicon.png' => 'serverbuddy/images/favicon.png',
  736. 'images/sort_down.png' => 'serverbuddy/images/sort_down.png',
  737. 'lib/dbreplace' => 'serverbuddy/lib/dbreplace',
  738. 'lib/commandbuddy' => 'serverbuddy/lib/commandbuddy',
  739. 'lib/zipbuddy' => 'serverbuddy/lib/zipbuddy',
  740. 'lib/mysqlbuddy' => 'serverbuddyy/lib/mysqlbuddy',
  741. 'lib/textreplacebuddy' => 'serverbuddy/lib/textreplacebuddy',
  742. 'pluginbuddy' => 'serverbuddy/pluginbuddy',
  743. 'controllers/pages/server_info' => 'serverbuddy/controllers/pages/server_info',
  744. 'controllers/pages/server_info.php' => 'serverbuddy/controllers/pages/server_info.php',
  745. );
  746. $output .= "\n<?php /*\n###PACKDATA,BEGIN\n";
  747. foreach( $_packdata as $pack_source => $pack_destination ) {
  748. $pack_source = '/' . $pack_source;
  749. if ( is_dir( pb_backupbuddy::plugin_path() . $pack_source ) ) {
  750. $files = pb_backupbuddy::$filesystem->deepglob( pb_backupbuddy::plugin_path() . $pack_source );
  751. } else {
  752. $files = array( pb_backupbuddy::plugin_path() . $pack_source );
  753. }
  754. foreach( $files as $file ) {
  755. if ( is_file( $file ) ) {
  756. $source = str_replace( pb_backupbuddy::plugin_path(), '', $file );
  757. $destination = $pack_destination . substr( $source, strlen( $pack_source ) );
  758. $output .= "###PACKDATA,FILE_START,{$source},{$destination}\n";
  759. $output .= base64_encode( file_get_contents( $file ) );
  760. $output .= "\n";
  761. $output .= "###PACKDATA,FILE_END,{$source},{$destination}\n";
  762. }
  763. }
  764. }
  765. $output .= "###PACKDATA,END\n*/";
  766. $output .= "\n\n\n\n\n\n\n\n\n\n";
  767. if ( $output_file == '' ) { // No file so output to browser.
  768. header( 'Content-Description: File Transfer' );
  769. header( 'Content-Type: text/plain; name=importbuddy.php' );
  770. header( 'Content-Disposition: attachment; filename=importbuddy.php' );
  771. header( 'Expires: 0' );
  772. header( 'Content-Length: ' . strlen( $output ) );
  773. flush();
  774. echo $output;
  775. flush();
  776. // BE SURE TO die() AFTER THIS AND NOT OUTPUT TO BROWSER!
  777. } else { // Write to file.
  778. file_put_contents( $output_file, $output );
  779. }
  780. } // End serverbuddy().
  781. // TODO: RepairBuddy is not yet converted into new framework so just using pre-BB3.0 version for now.
  782. public function repairbuddy( $output_file = '' ) {
  783. if ( defined( 'PB_DEMO_MODE' ) ) {
  784. echo 'Access denied in demo mode.';
  785. return;
  786. }
  787. if ( !isset( pb_backupbuddy::$options ) ) {
  788. pb_backupbuddy::load();
  789. }
  790. $output = file_get_contents( pb_backupbuddy::plugin_path() . '/_repairbuddy.php' );
  791. if ( pb_backupbuddy::$options['repairbuddy_pass_hash'] != '' ) {
  792. $output = preg_replace('/#PASSWORD#/', pb_backupbuddy::$options['repairbuddy_pass_hash'], $output, 1 ); // Only replaces first instance.
  793. }
  794. $output = preg_replace('/#VERSION#/', pb_backupbuddy::settings( 'version' ), $output, 1 ); // Only replaces first instance.
  795. if ( $output_file == '' ) { // No file so output to browser.
  796. header( 'Content-Description: File Transfer' );
  797. header( 'Content-Type: text/plain; name=repairbuddy.php' );
  798. header( 'Content-Disposition: attachment; filename=repairbuddy.php' );
  799. header( 'Expires: 0' );
  800. header( 'Content-Length: ' . strlen( $output ) );
  801. flush();
  802. echo $output;
  803. flush();
  804. // BE SURE TO die() AFTER THIS AND NOT OUTPUT TO BROWSER!
  805. } else { // Write to file.
  806. file_put_contents( $output_file, $output );
  807. }
  808. } // End repairbuddy().
  809. function pretty_destination_type( $type ) {
  810. if ( $type == 'rackspace' ) {
  811. return 'Rackspace';
  812. } elseif ( $type == 'email' ) {
  813. return 'Email';
  814. } elseif ( $type == 's3' ) {
  815. return 'Amazon S3';
  816. } elseif ( $type == 'ftp' ) {
  817. return 'FTP';
  818. } elseif ( $type == 'dropbox' ) {
  819. return 'Dropbox';
  820. } else {
  821. return $type;
  822. }
  823. } // End pretty_destination_type().
  824. // $max_depth int Maximum depth of tree to display. Npte that deeper depths are still traversed for size calculations.
  825. function build_icicle( $dir, $base, $icicle_json, $max_depth = 10, $depth_count = 0, $is_root = true ) {
  826. $bg_color = '005282';
  827. $depth_count++;
  828. $bg_color = dechex( hexdec( $bg_color ) - ( $depth_count * 15 ) );
  829. $icicle_json = '{' . "\n";
  830. $dir_name = $dir;
  831. $dir_name = str_replace( ABSPATH, '', $dir );
  832. $dir_name = str_replace( '\\', '/', $dir_name );
  833. $dir_size = 0;
  834. $sub = opendir( $dir );
  835. $has_children = false;
  836. while( $file = readdir( $sub ) ) {
  837. if ( ( $file == '.' ) || ( $file == '..' ) ) {
  838. continue; // Next loop.
  839. } elseif ( is_dir( $dir . '/' . $file ) ) {
  840. $dir_array = '';
  841. $response = $this->build_icicle( $dir . '/' . $file, $base, $dir_array, $max_depth, $depth_count, false );
  842. if ( ( $max_depth-1 > 0 ) || ( $max_depth == -1 ) ) { // Only adds to the visual tree if depth isnt exceeded.
  843. if ( $max_depth > 0 ) {
  844. $max_depth = $max_depth - 1;
  845. }
  846. if ( $has_children === false ) { // first loop add children section
  847. $icicle_json .= '"children": [' . "\n";
  848. } else {
  849. $icicle_json .= ',';
  850. }
  851. $icicle_json .= $response[0];
  852. $has_children = true;
  853. }
  854. $dir_size += $response[1];
  855. unset( $response );
  856. unset( $file );
  857. } else {
  858. $stats = stat( $dir . '/' . $file );
  859. $dir_size += $stats['size'];
  860. unset( $file );
  861. }
  862. }
  863. closedir( $sub );
  864. unset( $sub );
  865. if ( $has_children === true ) {
  866. $icicle_json .= ' ]' . "\n";
  867. }
  868. if ( $has_children === true ) {
  869. $icicle_json .= ',';
  870. }
  871. $icicle_json .= '"id": "node_' . str_replace( '/', ':', $dir_name ) . ': ^' . str_replace( ' ', '~', pb_backupbuddy::$format->file_size( $dir_size ) ) . '"' . "\n";
  872. $dir_name = str_replace( '/', '', strrchr( $dir_name, '/' ) );
  873. if ( $dir_name == '' ) { // Set root to be /.
  874. $dir_name = '/';
  875. }
  876. $icicle_json .= ', "name": "' . $dir_name . ' (' . pb_backupbuddy::$format->file_size( $dir_size ) . ')"' . "\n";
  877. $icicle_json .= ',"data": { "$dim": ' . ( $dir_size + 10 ) . ', "$color": "#' . str_pad( $bg_color, 6, '0', STR_PAD_LEFT ) . '" }' . "\n";
  878. $icicle_json .= '}';
  879. if ( $is_root !== true ) {
  880. //$icicle_json .= ',x';
  881. }
  882. return array( $icicle_json, $dir_size );
  883. } // End build_icicle().
  884. // return array of tests and their results.
  885. public function preflight_check() {
  886. $tests = array();
  887. // MULTISITE BETA WARNING.
  888. if ( is_multisite() && pb_backupbuddy::$classes['core']->is_network_activated() && !defined( 'PB_DEMO_MODE' ) ) { // Multisite installation.
  889. $tests[] = array(
  890. 'test' => 'multisite_beta',
  891. 'success' => false,
  892. 'message' => 'WARNING: BackupBuddy Multisite functionality is not supported. Multiple issues are known. Usage of it is at your own risk and should not be relied upon. Standalone WordPress sites are suggested. You may use the "Export" feature to export your subsites into standalone WordPress sites. To enable experimental BackupBuddy Multisite functionality you must add the following line to your wp-config.php file: <b>define( \'PB_BACKUPBUDDY_MULTISITE_EXPERIMENT\', true );</b>
  893. '
  894. );
  895. /*
  896. $tests[] = array(
  897. 'test' => 'multisite_beta_35',
  898. 'success' => false,
  899. 'message' => 'WARNING: Multisite running on WordPress v3.5 may have introduced multiple issues with importing sites into a Network, possibly including problems with media, users, and URL migration. Only using BackupBuddy with standalone sites is highly recommended.'
  900. );
  901. */
  902. } // end network-activated multisite.
  903. // LOOPBACKS TEST.
  904. if ( ( $loopback_response = $this->loopback_test() ) === true ) {
  905. $success = true;
  906. $message = '';
  907. } else { // failed
  908. $success = false;
  909. if ( defined( 'ALTERNATE_WP_CRON' ) && ( ALTERNATE_WP_CRON == true ) ) {
  910. $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>.';
  911. } else {
  912. $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>';
  913. }
  914. }
  915. $tests[] = array(
  916. 'test' => 'loopbacks',
  917. 'success' => $success,
  918. 'message' => $message,
  919. );
  920. // POSSIBLE CACHING PLUGIN CONFLICT WARNING.
  921. $success = true;
  922. $message = '';
  923. if ( ! is_multisite() ) {
  924. $active_plugins = serialize( get_option( 'active_plugins' ) );
  925. $warn_plugins = array(
  926. 'w3-total-cache.php' => 'W3 Total Cache',
  927. 'wp-cache.php' => 'WP Super Cache',
  928. );
  929. $found_plugins = array();
  930. foreach( $warn_plugins as $warn_plugin => $warn_plugin_title ) {
  931. if ( FALSE !== strpos( $active_plugins, $warn_plugin ) ) { // Plugin active.
  932. $found_plugins[] = $warn_plugin_title;
  933. $success = false;
  934. }
  935. }
  936. }
  937. if ( count( $found_plugins ) > 0 ) {
  938. $message = __( 'One or more caching plugins were detected as activated. Some caching plugin configurations may possibly cache & interfere with backup processes or WordPress cron. If you encounter problems clear the caching plugin\'s cache (deactivating the plugin may help) to troubleshoot.', 'it-l10n-backupbuddy' ) . ' ';
  939. $message .= __( 'Activated caching plugins detected:', 'it-l10n-backupbuddy' ) . ' ';
  940. $message .= implode( ', ', $found_plugins );
  941. $message .= '.';
  942. }
  943. $tests[] = array(
  944. 'test' => 'loopbacks',
  945. 'success' => $success,
  946. 'message' => $message,
  947. );
  948. // Reminder if no schedules are set up yet.
  949. /* CURRENTLY MOVED TO SCHEDULES PAGE.
  950. if ( count( pb_backupbuddy::$options['schedules'] ) == 0 ) {
  951. $success = false;
  952. $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' );
  953. } else {
  954. $success = true;
  955. $message = '';
  956. }
  957. $tests[] = array(
  958. 'test' => 'no_schedule_reminder',
  959. 'success' => $success,
  960. 'message' => $message,
  961. );
  962. */
  963. // WORDPRESS IN SUBDIRECTORIES TEST.
  964. $wordpress_locations = $this->get_wordpress_locations();
  965. if ( count( $wordpress_locations ) > 0 ) {
  966. $success = false;
  967. $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 );
  968. } else {
  969. $success = true;
  970. $message = '';
  971. }
  972. $tests[] = array(
  973. 'test' => 'wordpress_subdirectories',
  974. 'success' => $success,
  975. 'message' => $message,
  976. );
  977. // Log file directory writable for status logging.
  978. $status_directory = WP_CONTENT_DIR . '/uploads/pb_' . pb_backupbuddy::settings( 'slug' ) . '/';
  979. if ( ! is_writable( $status_directory ) ) {
  980. $success = false;
  981. $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.';
  982. } else {
  983. $success = true;
  984. $message = '';
  985. }
  986. $tests[] = array(
  987. 'test' => 'status_directory_writable',
  988. 'success' => $success,
  989. 'message' => $message,
  990. );
  991. // CHECK ZIP AVAILABILITY.
  992. require_once( pb_backupbuddy::plugin_path() . '/lib/zipbuddy/zipbuddy.php' );
  993. if ( !isset( pb_backupbuddy::$classes['zipbuddy'] ) ) {
  994. pb_backupbuddy::$classes['zipbuddy'] = new pluginbuddy_zipbuddy( pb_backupbuddy::$options['backup_directory'] );
  995. }
  996. /*
  997. if ( in_array( 'exec', pb_backupbuddy::$classes['zipbuddy']->_zip_methods ) ) {
  998. $success = false;
  999. $message = __('Your server does not support command line ZIP which is the fastest way for BackupBuddy to make backups. Backups will be performed using other available methods which may be slower. This is typically fine unless sites are large where timeouts or stalling may be encountered due to running out of time. You will be notified if such an error occurs. You may dismiss this message by clicking the "Dismiss" to the right.', 'it-l10n-backupbuddy' )
  1000. . '<a href="http://ithemes.com/codex/page/BackupBuddy:_Frequent_Support_Issues#Compatibility_Mode" target="_new">'
  1001. . ' ' . __('Click for more information.', 'it-l10n-backupbuddy' )
  1002. . '</a>';
  1003. } else { // Success.
  1004. $success = true;
  1005. $message = '';
  1006. }
  1007. $tests[] = array(
  1008. 'test' => 'zip_methods',
  1009. 'success' => $success,
  1010. 'message' => $message,
  1011. );
  1012. */
  1013. // Show warning if recent backups reports it is not complete yet. (3min is recent)
  1014. 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.
  1015. if ( !empty( pb_backupbuddy::$options['backups'][pb_backupbuddy::$options['last_backup_serial']]['steps'] ) ) {
  1016. $found_unfinished = false;
  1017. foreach( pb_backupbuddy::$options['backups'][pb_backupbuddy::$options['last_backup_serial']]['steps'] as $step ) {
  1018. if ( $step['finish_time'] == '0' ) { // Found an unfinished step.
  1019. $found_unfinished = true;
  1020. break;
  1021. }
  1022. }
  1023. if ( $found_unfinished === true ) {
  1024. $tests[] = array(
  1025. 'test' => 'recent_backup',
  1026. 'success' => false,
  1027. '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' ) .
  1028. ' Last updated: ' . pb_backupbuddy::$format->date( pb_backupbuddy::$options['backups'][pb_backupbuddy::$options['last_backup_serial']]['updated_time'] ) . '; '.
  1029. ' Serial: ' . pb_backupbuddy::$options['last_backup_serial']
  1030. ,
  1031. );
  1032. }
  1033. }
  1034. }
  1035. // Check if any backups are in site root (ie from a recent restore).
  1036. $files = glob( ABSPATH . 'backup-*.zip' );
  1037. if ( !is_array( $files ) || empty( $files ) ) {
  1038. $files = array();
  1039. }
  1040. foreach( $files as &$file ) {
  1041. $file = basename( $file );
  1042. }
  1043. if ( count( $files ) > 0 ) {
  1044. $files_string = implode( ', ', $files );
  1045. $tests[] = array(
  1046. 'test' => 'root_backups-' . $files_string,
  1047. 'success' => false,
  1048. 'message' => 'One or more backup files, `' . $files_string . '` was found in the root directory of this site. This may be leftover from a recent restore. You should usually remove backup files from the site root for security.',
  1049. );
  1050. }
  1051. // Warn if any BackupBuddy ZIP files are found in root of directory (ie from an import).
  1052. return $tests;
  1053. } // End preflight_check().
  1054. // returns true on success, error message otherwise.
  1055. /* loopback_test()
  1056. *
  1057. * Connects back to same site via AJAX call to an AJAX slug that has NOT been registered.
  1058. * WordPress AJAX returns a -1 (or 0 in newer version?) for these. Also not logged into
  1059. * admin when connecting back. Checks to see if body contains -1 / 0. If loopbacks are not
  1060. * enabled then will fail connecting or do something else.
  1061. *
  1062. *
  1063. * @param
  1064. * @return boolean True on success, string error message otherwise.
  1065. */
  1066. function loopback_test() {
  1067. $loopback_url = admin_url('admin-ajax.php');
  1068. pb_backupbuddy::status( 'details', 'Testing loopback connections by connecting back to site at the URL: `' . $loopback_url . '`. It should display simply "0" or "-1" in the body.' );
  1069. $response = wp_remote_get(
  1070. $loopback_url,
  1071. array(
  1072. 'method' => 'GET',
  1073. 'timeout' => 5, // 5 second delay. A loopback should be very fast.
  1074. 'redirection' => 5,
  1075. 'httpversion' => '1.0',
  1076. 'blocking' => true,
  1077. 'headers' => array(),
  1078. 'body' => null,
  1079. 'cookies' => array()
  1080. )
  1081. );
  1082. if( is_wp_error( $response ) ) { // Loopback failed. Some kind of error.
  1083. $error = $response->get_error_message();
  1084. pb_backupbuddy::status( 'error', 'Loopback test error: `' . $error . '`.' );
  1085. return 'Error: ' . $error;
  1086. } else {
  1087. if ( ( $response['body'] == '-1' ) || ( $response['body'] == '0' ) ) { // Loopback succeeded.
  1088. pb_backupbuddy::status( 'details', 'HTTP Loopback test success. Returned `' . $response['body'] . '`.' );
  1089. return true;
  1090. } else { // Loopback failed.
  1091. $error = 'A loopback seemed to occur but the value `' . $response['body'] . '` was not correct.';
  1092. pb_backupbuddy::status( 'error', $error );
  1093. return $error;
  1094. }
  1095. }
  1096. }
  1097. // Returns array of subdirectories that contain WordPress.
  1098. function get_wordpress_locations() {
  1099. $wordpress_locations = array();
  1100. $files = glob( ABSPATH . '*/' );
  1101. if ( !is_array( $files ) || empty( $files ) ) {
  1102. $files = array();
  1103. }
  1104. foreach( $files as $file ) {
  1105. if ( file_exists( $file . 'wp-config.php' ) ) {
  1106. $wordpress_locations[] = rtrim( '/' . str_replace( ABSPATH, '', $file ), '/\\' );
  1107. }
  1108. }
  1109. // Remove any excluded directories from showing up in this.
  1110. $directory_exclusions = $this->get_directory_exclusions();
  1111. $wordpress_locations = array_diff( $wordpress_locations, $directory_exclusions );
  1112. return $wordpress_locations;
  1113. }
  1114. // TODO: coming soon.
  1115. // Run through potential orphaned files, data structures, etc caused by failed backups and clean things up.
  1116. // Also verifies anti-directory browsing files exists, etc.
  1117. function periodic_cleanup( $backup_age_limit = 43200, $die_on_fail = true ) {
  1118. $max_importbuddy_age = 60*60*1; // 1hr - Max age, in seconds, importbuddy files can be there before cleaning up (delay useful if just imported and testing out site).
  1119. $max_status_log_age = 48; // Max age in hours.
  1120. $max_site_log_size = pb_backupbuddy::$options['max_site_log_size'] * 1024 * 1024; // in bytes.
  1121. pb_backupbuddy::status( 'message', 'Starting cleanup procedure for BackupBuddy v' . pb_backupbuddy::settings( 'version' ) . '.' );
  1122. if ( !isset( pb_backupbuddy::$options ) ) {
  1123. $this->load();
  1124. }
  1125. // TODO: Check for orphaned .gz files in root from PCLZip.
  1126. // Cleanup backup itegrity portion of array (status logging info inside function).
  1127. $this->trim_backups_integrity_stats();
  1128. // Cleanup logs in pb_backupbuddy dirctory.
  1129. pb_backupbuddy::status( 'details', 'Cleaning up old logs.' );
  1130. $log_directory = WP_CONTENT_DIR . '/uploads/pb_' . pb_backupbuddy::settings( 'slug' ) . '/';
  1131. // Purge individual backup status logs unmodified in certain number of hours.
  1132. $files = glob( $log_directory . 'status-*.txt' );
  1133. 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.
  1134. foreach( $files as $file ) {
  1135. $file_stats = stat( $file );
  1136. if ( ( time() - $file_stats['mtime'] ) > $max_status_log_age ) {
  1137. @unlink( $file );
  1138. }
  1139. }
  1140. }
  1141. // Purge site-wide log if over certain size.
  1142. $files = glob( $log_directory . 'log-*.txt' );
  1143. 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.
  1144. foreach( $files as $file ) {
  1145. $file_stats = stat( $file );
  1146. if ( $file_stats['size'] > ( $max_site_log_size ) ) {
  1147. $this->mail_error( 'NOTICE ONLY (not an error): A BackupBuddy log file has exceeded the size threshold of ' . $max_site_log_size . ' KB and has been deleted to maintain performance. This is only a notice. Deleted log file: ' . $file . '.' );
  1148. @unlink( $file );
  1149. }
  1150. }
  1151. }
  1152. // Cleanup excess backup stats.
  1153. pb_backupbuddy::status( 'details', 'Cleaning up backup stats.' );
  1154. if ( count( pb_backupbuddy::$options['backups'] ) > 3 ) { // Keep a minimum number of backups in array for stats.
  1155. $number_backups = count( pb_backupbuddy::$options['backups'] );
  1156. $kept_loop_count = 0;
  1157. $needs_save = false;
  1158. foreach( pb_backupbuddy::$options['backups'] as $backup_serial => $backup ) {
  1159. if ( ( $number_backups - $kept_loop_count ) > 3 ) {
  1160. if ( isset( $backup['archive_file'] ) && !file_exists( $backup['archive_file'] ) ) {
  1161. unset( pb_backupbuddy::$options['backups'][$backup_serial] );
  1162. $needs_save = true;
  1163. } else {
  1164. $kept_loop_count++;
  1165. }
  1166. }
  1167. }
  1168. if ( $needs_save === true ) {
  1169. //echo 'saved';
  1170. pb_backupbuddy::save();
  1171. }
  1172. }
  1173. // Cleanup any temporary local destinations.
  1174. pb_backupbuddy::status( 'details', 'Cleaning up any temporary local destinations.' );
  1175. foreach( pb_backupbuddy::$options['remote_destinations'] as $destination_id => $destination ) {
  1176. if ( ( $destination['type'] == 'local' ) && ( isset( $destination['temporary'] ) && ( $destination['temporary'] === true ) ) ) { // If local and temporary.
  1177. if ( ( time() - $destination['created'] ) > $backup_age_limit ) { // Older than 12 hours; clear out!
  1178. pb_backupbuddy::status( 'details', 'Cleaned up stale local destination `' . $destination_id . '`.' );
  1179. unset( pb_backupbuddy::$options['remote_destinations'][$destination_id] );
  1180. pb_backupbuddy::save();
  1181. }
  1182. }
  1183. }
  1184. // Cleanup excess remote sending stats.
  1185. pb_backupbuddy::status( 'details', 'Cleaning up remote send stats.' );
  1186. $this->trim_remote_send_stats();
  1187. // Check for orphaned backups in the data structure that havent been updated in 12+ hours & cleanup after them.
  1188. pb_backupbuddy::status( 'details', 'Cleaning up data structure.' );
  1189. foreach( (array)pb_backupbuddy::$options['backups'] as $backup_serial => $backup ) {
  1190. if ( isset( $backup['updated_time'] ) ) {
  1191. if ( ( time() - $backup['updated_time'] ) > $backup_age_limit ) { // If more than 12 hours has passed...
  1192. pb_backupbuddy::status( 'details', 'Cleaned up stale backup `' . $backup_serial . '`.' );
  1193. $this->final_cleanup( $backup_serial );
  1194. }
  1195. }
  1196. }
  1197. // Verify existance of anti-directory browsing files in backup directory.
  1198. pb_backupbuddy::status( 'details', 'Verifying anti-directory browsing security on backup directory.' );
  1199. pb_backupbuddy::anti_directory_browsing( pb_backupbuddy::$options['backup_directory'], $die_on_fail );
  1200. // Verify existance of anti-directory browsing files in status log directory.
  1201. pb_backupbuddy::status( 'details', 'Verifying anti-directory browsing security on status log directory.' );
  1202. $status_directory = WP_CONTENT_DIR . '/uploads/pb_' . pb_backupbuddy::settings( 'slug' ) . '/';
  1203. pb_backupbuddy::anti_directory_browsing( $status_directory, $die_on_fail );
  1204. // Handle high security mode archives directory .htaccess system. If high security backup directory mode: Make sure backup archives are NOT downloadable by default publicly. This is only lifted for ~8 seconds during a backup download for security. Overwrites any existing .htaccess in this location.
  1205. if ( pb_backupbuddy::$options['lock_archives_directory'] == '0' ) { // Normal security mode. Put normal .htaccess.
  1206. pb_backupbuddy::status( 'details', 'Removing .htaccess high security mode for backups directory. Normal mode .htaccess to be added next.' );
  1207. // Remove high security .htaccess.
  1208. if ( file_exists( pb_backupbuddy::$options['backup_directory'] . '.htaccess' ) ) {
  1209. $unlink_status = @unlink( pb_backupbuddy::$options['backup_directory'] . '.htaccess' );
  1210. if ( $unlink_status === false ) {
  1211. pb_backupbuddy::alert( 'Error #844594. Unable to temporarily remove .htaccess security protection on archives directory to allow downloading. Please verify permissions of the BackupBuddy archives directory or manually download via FTP.' );
  1212. }
  1213. }
  1214. // Place normal .htaccess.
  1215. pb_backupbuddy::anti_directory_browsing( pb_backupbuddy::$options['backup_directory'], $die_on_fail );
  1216. } else { // High security mode. Make sure high security .htaccess in place.
  1217. pb_backupbuddy::status( 'details', 'Adding .htaccess high security mode for backups directory.' );
  1218. $htaccess_creation_status = @file_put_contents( pb_backupbuddy::$options['backup_directory'] . '.htaccess', 'deny from all' );
  1219. if ( $htaccess_creation_status === false ) {
  1220. pb_backupbuddy::alert( 'Error #344894545. Security Warning! Unable to create security file (.htaccess) in backups archive directory. This file prevents unauthorized downloading of backups should someone be able to guess the backup location and filenames. This is unlikely but for best security should be in place. Please verify permissions on the backups directory.' );
  1221. }
  1222. }
  1223. // Verify existance of anti-directory browsing files in temporary directory.
  1224. pb_backupbuddy::status( 'details', 'Verifying anti-directory browsing security on temp directory.' );
  1225. pb_backupbuddy::anti_directory_browsing( pb_backupbuddy::$options['temp_directory'], $die_on_fail );
  1226. // Remove any copy of importbuddy.php in root.
  1227. pb_backupbuddy::status( 'details', 'Cleaning up importbuddy.php script in site root if it exists & is not very recent.' );
  1228. if ( file_exists( ABSPATH . 'importbuddy.php' ) ) {
  1229. $modified = filemtime( ABSPATH . 'importbuddy.php' );
  1230. if ( ( FALSE === $modified ) || ( time() > ( $modified + $max_importbuddy_age ) ) ) { // If time modified unknown OR was modified long enough ago.
  1231. pb_backupbuddy::status( 'details', 'Unlinked importbuddy.php in root of site.' );
  1232. unlink( ABSPATH . 'importbuddy.php' );
  1233. } else {
  1234. pb_backupbuddy::status( 'details', 'SKIPPED unlinking importbuddy.php in root of site as it is fresh and may still be in use.' );
  1235. }
  1236. }
  1237. // Remove any copy of importbuddy directory in root.
  1238. pb_backupbuddy::status( 'details', 'Cleaning up importbuddy directory in site root if it exists & is not very recent.' );
  1239. if ( file_exists( ABSPATH . 'importbuddy/' ) ) {
  1240. $modified = filemtime( ABSPATH . 'importbuddy/' );
  1241. if ( ( FALSE === $modified ) || ( time() > ( $modified + $max_importbuddy_age ) ) ) { // If time modified unknown OR was modified long enough ago.
  1242. pb_backupbuddy::status( 'details', 'Unlinked importbuddy directory recursively in root of site.' );
  1243. pb_backupbuddy::$filesystem->unlink_recursive( ABSPATH . 'importbuddy/' );
  1244. } else {
  1245. pb_backupbuddy::status( 'details', 'SKIPPED unlinked importbuddy directory recursively in root of site as it is fresh and may still be in use.' );
  1246. }
  1247. }
  1248. // Remove any old temporary directories in wp-content/uploads/backupbuddy_temp/. Logs any directories it cannot delete.
  1249. pb_backupbuddy::status( 'details', 'Cleaning up any old temporary zip directories in: wp-content/uploads/backupbuddy_temp/' );
  1250. $temp_directory = WP_CONTENT_DIR . '/uploads/backupbuddy_temp/';
  1251. $files = glob( $temp_directory . '*' );
  1252. 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.
  1253. foreach( $files as $file ) {
  1254. if ( ( strpos( $file, 'index.' ) !== false ) || ( strpos( $file, '.htaccess' ) !== false ) ) { // Index file or htaccess dont get deleted so go to next file.
  1255. continue;
  1256. }
  1257. $file_stats = stat( $file );
  1258. if ( ( time() - $file_stats['mtime'] ) > $backup_age_limit ) { // If older than 12 hours, delete the log.
  1259. if ( @pb_backupbuddy::$filesystem->unlink_recursive( $file ) === false ) {
  1260. pb_backupbuddy::status( 'error', 'Unable to clean up (delete) temporary directory/file: `' . $file . '`. You should manually delete it or check permissions.' );
  1261. }
  1262. }
  1263. }
  1264. }
  1265. // Remove any old temporary zip directories: wp-content/uploads/backupbuddy_backups/temp_zip_XXXX/. Logs any directories it cannot delete.
  1266. pb_backupbuddy::status( 'details', 'Cleaning up any old temporary zip directories in backup directory temp location `' . pb_backupbuddy::$options['backup_directory'] . 'temp_zip_XXXX/`.' );
  1267. // $temp_directory = WP_CONTENT_DIR . '/uploads/backupbuddy_backups/temp_zip_*';
  1268. $temp_directory = pb_backupbuddy::$options['backup_directory'] . 'temp_zip_*';
  1269. $files = glob( $temp_directory . '*' );
  1270. 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.
  1271. foreach( $files as $file ) {
  1272. if ( ( strpos( $file, 'index.' ) !== false ) || ( strpos( $file, '.htaccess' ) !== false ) ) { // Index file or htaccess dont get deleted so go to next file.
  1273. continue;
  1274. }
  1275. $file_stats = stat( $file );
  1276. if ( ( time() - $file_stats['mtime'] ) > $backup_age_limit ) { // If older than 12 hours, delete the log.
  1277. if ( @pb_backupbuddy::$filesystem->unlink_recursive( $file ) === false ) {
  1278. $message = 'BackupBuddy was unable to clean up (delete) temporary directory/file: `' . $file . '`. You should manually delete it and/or verify proper file permissions to allow BackupBuddy to clean up for you.';
  1279. pb_backupbuddy::status( 'error', $message );
  1280. $this->mail_error( $message );
  1281. }
  1282. }
  1283. }
  1284. }
  1285. @clearstatcache(); // Clears file info stat cache.
  1286. pb_backupbuddy::status( 'message', 'Finished cleanup procedure.' );
  1287. } // End periodic_cleanup().
  1288. public function final_cleanup( $serial ) {
  1289. if ( !isset( pb_backupbuddy::$options ) ) {
  1290. pb_backupbuddy::load();
  1291. }
  1292. pb_backupbuddy::status( 'details', 'cron_final_cleanup started' );
  1293. // Delete temporary data directory.
  1294. if ( isset( pb_backupbuddy::$options['backups'][$serial]['temp_directory'] ) && file_exists( pb_backupbuddy::$options['backups'][$serial]['temp_directory'] ) ) {
  1295. pb_backupbuddy::$filesystem->unlink_recursive( pb_backupbuddy::$options['backups'][$serial]['temp_directory'] );
  1296. }
  1297. // Delete temporary zip directory.
  1298. if ( isset( pb_backupbuddy::$options['backups'][$serial]['temporary_zip_directory'] ) && file_exists( pb_backupbuddy::$options['backups'][$serial]['temporary_zip_directory'] ) ) {
  1299. pb_backupbuddy::$filesystem->unlink_recursive( pb_backupbuddy::$options['backups'][$serial]['temporary_zip_directory'] );
  1300. }
  1301. // Delete status log text file.
  1302. if ( file_exists( pb_backupbuddy::$options['backup_directory'] . 'temp_status_' . $serial . '.txt' ) ) {
  1303. unlink( pb_backupbuddy::$options['backup_directory'] . 'temp_status_' . $serial. '.txt' );
  1304. }
  1305. } // End final_cleanup().
  1306. /* trim_remote_send_stats()
  1307. *
  1308. * Handles trimming the number of remote sends to the most recent ones.
  1309. *
  1310. * @return null
  1311. */
  1312. public function trim_remote_send_stats() {
  1313. $limit = 5; // Maximum number of remote sends to keep track of.
  1314. // Return if limit not yet met.
  1315. if ( count( pb_backupbuddy::$options['remote_sends'] ) <= $limit ) {
  1316. return;
  1317. }
  1318. // Uses the negative offset of array_slice() to grab the last X number of items from array.
  1319. pb_backupbuddy::$options['remote_sends'] = array_slice( pb_backupbuddy::$options['remote_sends'], ( $limit * -1 ) );
  1320. pb_backupbuddy::save();
  1321. } // End trim_remote_send_stats().
  1322. /* trim_backups_integrity_stats()
  1323. *
  1324. * Handles trimming the number of backup integrity items in the data structure. Trims to all backups left or 10, whichever is more.
  1325. *
  1326. * @param
  1327. * @return
  1328. */
  1329. public function trim_backups_integrity_stats() {
  1330. pb_backupbuddy::status( 'details', 'Trimming backup integrity stats.' );
  1331. $minimum = 10; // Minimum number of backups' integrity to keep track of.
  1332. if ( !isset( pb_backupbuddy::$options['backups'] ) ) { // No integrity checks yet.
  1333. return;
  1334. }
  1335. // Put newest backups first.
  1336. $existing_backups = array_reverse( pb_backupbuddy::$options['backups'] );
  1337. // Remove any backup integrity stats for deleted backups. Will re-add from temp array if we drop under the minimum.
  1338. foreach( $existing_backups as $backup_serial => $existing_backup ) {
  1339. if ( !isset( $existing_backup['archive_file'] ) || ( !file_exists( $existing_backup['archive_file'] ) ) ) {
  1340. unset( pb_backupbuddy::$options['backups'][$backup_serial] ); // File gone so erase from options. Will re-add if we go under our minimum.
  1341. }
  1342. } // End foreach.
  1343. // Need to make sure the database connection is active. Sometimes it goes away during long bouts doing other things -- sigh.
  1344. // This is not essential so use include and not require (suppress any warning)
  1345. pb_backupbuddy::status( 'details', 'Loading DB kicker in case database has gone away.' );
  1346. @include_once( pb_backupbuddy::plugin_path() . '/lib/wpdbutils/wpdbutils.php' );
  1347. if ( class_exists( 'pluginbuddy_wpdbutils' ) ) {
  1348. // This is the database object we want to use
  1349. global $wpdb;
  1350. // Get our helper object and let it use us to output status messages
  1351. $dbhelper = new pluginbuddy_wpdbutils( $wpdb );
  1352. // If we cannot kick the database into life then signal the error and return false which will stop the backup
  1353. // Otherwise all is ok and we can just fall through and let the function return true
  1354. if ( !$dbhelper->kick() ) {
  1355. pb_backupbuddy::status( 'error', __('Database Server has gone away, unable to save remote transfer status.', 'it-l10n-backupbuddy' ) );
  1356. return false;
  1357. } else {
  1358. pb_backupbuddy::status( 'details', 'Database seems to still be connected.' );
  1359. }
  1360. } else {
  1361. // Utils not available so cannot verify database connection status - just notify
  1362. pb_backupbuddy::status( 'details', __('Database Server connection status unverified.', 'it-l10n-backupbuddy' ) );
  1363. }
  1364. // If dropped under the minimum try to add back in some to get enough sample points.
  1365. if ( count( pb_backupbuddy::$options['backups'] ) < $minimum ) {
  1366. foreach( $existing_backups as $backup_serial => $existing_backup ) {
  1367. if ( !isset( pb_backupbuddy::$options['backups'][$backup_serial] ) ) {
  1368. pb_backupbuddy::$options['backups'][$backup_serial] = $existing_backup; // Add item.
  1369. }
  1370. // If hit minimum then stop looping to add.
  1371. if ( count( pb_backupbuddy::$options['backups'] ) >= $minimum ) {
  1372. break;
  1373. }
  1374. }
  1375. // Put array back in normal order.
  1376. pb_backupbuddy::$options['backups'] = array_reverse( pb_backupbuddy::$options['backups'] );
  1377. pb_backupbuddy::save();
  1378. } else { // Still have enough stats. Save.
  1379. pb_backupbuddy::$options['backups'] = array_reverse( pb_backupbuddy::$options['backups'] );
  1380. pb_backupbuddy::save();
  1381. }
  1382. } // End trim_backups_integrity_stats().
  1383. /* get_site_size()
  1384. *
  1385. * Returns an array with the site size and the site size sans exclusions. Saves updates stats in options.
  1386. *
  1387. * @return array Index 0: site size; Index 1: site size sans excluded files/dirs.
  1388. */
  1389. public function get_site_size() {
  1390. $exclusions = pb_backupbuddy_core::get_directory_exclusions();
  1391. $dir_array = array();
  1392. $result = pb_backupbuddy::$filesystem->dir_size_map( ABSPATH, ABSPATH, $exclusions, $dir_array );
  1393. unset( $dir_array ); // Free this large chunk of memory.
  1394. $total_size = pb_backupbuddy::$options['stats']['site_size'] = $result[0];
  1395. $total_size_excluded = pb_backupbuddy::$options['stats']['site_size_excluded'] = $result[1];
  1396. pb_backupbuddy::$options['stats']['site_size_updated'] = time();
  1397. pb_backupbuddy::save();
  1398. return array( $total_size, $total_size_excluded );
  1399. } // End get_site_size().
  1400. /* get_database_size()
  1401. *
  1402. * Return array of database size, database sans exclusions.
  1403. *
  1404. * @return array Index 0: db size, Index 1: db size sans exclusions.
  1405. */
  1406. public function get_database_size() {
  1407. global $wpdb;
  1408. $prefix = $wpdb->prefix;
  1409. $prefix_length = strlen( $wpdb->prefix );
  1410. $additional_includes = explode( "\n", pb_backupbuddy::$options['mysqldump_additional_includes'] );
  1411. array_walk( $additional_includes, create_function('&$val', '$val = trim($val);'));
  1412. $additional_excludes = explode( "\n", pb_backupbuddy::$options['mysqldump_additional_excludes'] );
  1413. array_walk( $additional_excludes, create_function('&$val', '$val = trim($val);'));
  1414. $total_size = 0;
  1415. $total_size_with_exclusions = 0;
  1416. $result = mysql_query("SHOW TABLE STATUS");
  1417. while( $rs = mysql_fetch_array( $result ) ) {
  1418. $excluded = true; // Default.
  1419. // TABLE STATUS.
  1420. $resultb = mysql_query("CHECK TABLE `{$rs['Name']}`");
  1421. while( $rsb = mysql_fetch_array( $resultb ) ) {
  1422. if ( $rsb['Msg_type'] == 'status' ) {
  1423. $status = $rsb['Msg_text'];
  1424. }
  1425. }
  1426. mysql_free_result( $resultb );
  1427. // TABLE SIZE.
  1428. $size = ( $rs['Data_length'] + $rs['Index_length'] );
  1429. $total_size += $size;
  1430. // HANDLE EXCLUSIONS.
  1431. if ( pb_backupbuddy::$options['backup_nonwp_tables'] == 0 ) { // Only matching prefix.
  1432. if ( ( substr( $rs['Name'], 0, $prefix_length ) == $prefix ) OR ( in_array( $rs['Name'], $additional_includes ) ) ) {
  1433. if ( !in_array( $rs['Name'], $additional_excludes ) ) {
  1434. $total_size_with_exclusions += $size;
  1435. $excluded = false;
  1436. }
  1437. }
  1438. } else { // All tables.
  1439. if ( !in_array( $rs['Name'], $additional_excludes ) ) {
  1440. $total_size_with_exclusions += $size;
  1441. $excluded = false;
  1442. }
  1443. }
  1444. }
  1445. pb_backupbuddy::$options['stats']['db_size'] = $total_size;
  1446. pb_backupbuddy::$options['stats']['db_size_excluded'] = $total_size_with_exclusions;
  1447. pb_backupbuddy::$options['stats']['db_size_updated'] = time();
  1448. pb_backupbuddy::save();
  1449. mysql_free_result( $result );
  1450. return array( $total_size, $total_size_with_exclusions );
  1451. } // End get_database_size().
  1452. /* Doesnt work?
  1453. public function error_handler( $error_number, $error_string, $error_file, $error_line ) {
  1454. pb_backupbuddy::status( 'error', "PHP error caught. Error #`{$error_number}`; Description: `{$error_string}`; File: `{$error_file}`; Line: `{$error_line}`." );
  1455. return true;
  1456. }
  1457. */
  1458. public function kick_db() {
  1459. $kick_db = true; // Change true to false for debugging purposes to disable kicker.
  1460. // Need to make sure the database connection is active. Sometimes it goes away during long bouts doing other things -- sigh.
  1461. // This is not essential so use include and not require (suppress any warning)
  1462. if ( $kick_db === true ) {
  1463. pb_backupbuddy::status( 'details', 'kick_db()' );
  1464. pb_backupbuddy::status( 'details', 'Loading DB kicker in case database has gone away.' );
  1465. @include_once( pb_backupbuddy::plugin_path() . '/lib/wpdbutils/wpdbutils.php' );
  1466. if ( class_exists( 'pluginbuddy_wpdbutils' ) ) {
  1467. // This is the database object we want to use
  1468. global $wpdb;
  1469. // Get our helper object and let it use us to output status messages
  1470. $dbhelper = new pluginbuddy_wpdbutils( $wpdb );
  1471. // If we cannot kick the database into life then signal the error and return false which will stop the backup
  1472. // Otherwise all is ok and we can just fall through and let the function return true
  1473. if ( !$dbhelper->kick() ) {
  1474. pb_backupbuddy::status( 'error', __('Database Server has gone away, unable to update remote destination transfer status. This is most often caused by mysql running out of memory or timing out far too early. Please contact your host.', 'it-l10n-backupbuddy' ) );
  1475. } else {
  1476. pb_backupbuddy::status( 'details', 'Database seems to still be connected.' );
  1477. }
  1478. } else {
  1479. // Utils not available so cannot verify database connection status - just notify
  1480. pb_backupbuddy::status( 'details', __('Database Server connection status unverified.', 'it-l10n-backupbuddy' ) );
  1481. }
  1482. }
  1483. } // End kick_db().
  1484. public function verify_directories() {
  1485. // Keep backup directory up to date.
  1486. //if ( pb_backupbuddy::$options['backup_directory'] != ( ABSPATH . 'wp-content/uploads/backupbuddy_backups/' ) ) {
  1487. if ( ( pb_backupbuddy::$options['backup_directory'] == '' ) || ( ! @is_writable( pb_backupbuddy::$options['backup_directory'] ) ) ) {
  1488. $default_backup_dir = ABSPATH . 'wp-content/uploads/backupbuddy_backups/';
  1489. pb_backupbuddy::status( 'details', 'Backup directory invalid. Updating from `' . pb_backupbuddy::$options['backup_directory'] . '` to the default `' . $default_backup_dir . '`.' );
  1490. pb_backupbuddy::$options['backup_directory'] = $default_backup_dir;
  1491. pb_backupbuddy::save();
  1492. }
  1493. // Make backup directory if it does not exist yet.
  1494. //pb_backupbuddy::status( 'details', 'Verifying backup directory `' . pb_backupbuddy::$options['backup_directory'] . '` exists.' );
  1495. if ( !file_exists( pb_backupbuddy::$options['backup_directory'] ) ) {
  1496. pb_backupbuddy::status( 'details', 'Backup directory does not exist. Attempting to create.' );
  1497. if ( pb_backupbuddy::$filesystem->mkdir( pb_backupbuddy::$options['backup_directory'] ) === false ) {
  1498. pb_backupbuddy::status( 'error', sprintf( __('Unable to create backup storage directory (%s)', 'it-l10n-backupbuddy' ) , pb_backupbuddy::$options['backup_directory'] ) );
  1499. pb_backupbuddy::alert( sprintf( __('Unable to create backup storage directory (%s)', 'it-l10n-backupbuddy' ) , pb_backupbuddy::$options['backup_directory'] ), true, '9002' );
  1500. }
  1501. }
  1502. // Keep temp directory up to date.
  1503. if ( pb_backupbuddy::$options['temp_directory'] != ( ABSPATH . 'wp-content/uploads/backupbuddy_temp/' ) ) {
  1504. pb_backupbuddy::status( 'details', 'Temporary directory has changed. Updating from `' . pb_backupbuddy::$options['temp_directory'] . '` to `' . ABSPATH . 'wp-content/uploads/backupbuddy_temp/' . '`.' );
  1505. pb_backupbuddy::$options['temp_directory'] = ABSPATH . 'wp-content/uploads/backupbuddy_temp/';
  1506. pb_backupbuddy::save();
  1507. }
  1508. // Make backup directory if it does not exist yet.
  1509. if ( !file_exists( pb_backupbuddy::$options['temp_directory'] ) ) {
  1510. pb_backupbuddy::status( 'details', 'Temporary directory does not exist. Attempting to create.' );
  1511. if ( pb_backupbuddy::$filesystem->mkdir( pb_backupbuddy::$options['temp_directory'] ) === false ) {
  1512. pb_backupbuddy::status( 'error', sprintf( __('Unable to create temporary storage directory (%s)', 'it-l10n-backupbuddy' ) , pb_backupbuddy::$options['temp_directory'] ) );
  1513. pb_backupbuddy::alert( sprintf( __('Unable to create temporary storage directory (%s)', 'it-l10n-backupbuddy' ) , pb_backupbuddy::$options['temp_directory'] ), true, '9002' );
  1514. }
  1515. }
  1516. } // End verify_directories().
  1517. /* schedule_single_event()
  1518. *
  1519. * API to wp_schedule_single_event() that also verifies that the schedule actually got created in WordPRess.
  1520. * Sometimes the database rejects this update so we need to do actual verification.
  1521. *
  1522. * @return boolean True on verified schedule success, else false.
  1523. */
  1524. public function schedule_single_event( $time, $tag, $args ) {
  1525. $schedule_result = wp_schedule_single_event( $time, $tag, $args );
  1526. $next_scheduled = wp_next_scheduled( $tag, $args );
  1527. if ( FALSE === $schedule_result ) {
  1528. pb_backupbuddy::status( 'error', 'Unable to create schedule as wp_schedule_single_event() returned false. A plugin may have prevented it.' );
  1529. return false;
  1530. }
  1531. if ( FALSE === $next_scheduled ) {
  1532. pb_backupbuddy::status( 'error', 'WordPress reported success scheduling BUT wp_next_scheduled() could NOT confirm schedule existance. The database may have rejected the update.' );
  1533. return false;
  1534. }
  1535. return true;
  1536. } // End schedule_single_event().
  1537. /* schedule_event()
  1538. *
  1539. * API to wp_schedule_event() that also verifies that the schedule actually got created in WordPRess.
  1540. * Sometimes the database rejects this update so we need to do actual verification.
  1541. *
  1542. * @return boolean True on verified schedule success, else false.
  1543. */
  1544. public function schedule_event( $time, $period, $tag, $args ) {
  1545. $schedule_result = wp_schedule_event( $time, $period, $tag, $args );
  1546. $next_scheduled = wp_next_scheduled( $tag, $args );
  1547. if ( FALSE === $schedule_result ) {
  1548. pb_backupbuddy::status( 'error', 'Unable to create schedule as wp_schedule_event() returned false. A plugin may have prevented it.' );
  1549. return false;
  1550. }
  1551. if ( FALSE === $next_scheduled ) {
  1552. pb_backupbuddy::status( 'error', 'WordPress reported success scheduling BUT wp_next_scheduled() could NOT confirm schedule existance. The database may have rejected the update.' );
  1553. return false;
  1554. }
  1555. return true;
  1556. } // End schedule_event().
  1557. /* unschedule_event()
  1558. *
  1559. * API to wp_unschedule_event() that also verifies that the schedule actually got removed WordPRess.
  1560. * Sometimes the database rejects this update so we need to do actual verification.
  1561. *
  1562. * @return boolean True on verified schedule deletion success, else false.
  1563. */
  1564. public function unschedule_event( $time, $tag, $args ) {
  1565. $unschedule_result = wp_unschedule_event( $time, $tag, $args );
  1566. $next_scheduled = wp_next_scheduled( $tag, $args );
  1567. if ( FALSE === $unschedule_result ) {
  1568. pb_backupbuddy::status( 'error', 'Unable to remove schedule as wp_unschedule_event() returned false. A plugin may have prevented it.' );
  1569. return false;
  1570. }
  1571. if ( FALSE !== $next_scheduled ) {
  1572. pb_backupbuddy::status( 'error', 'WordPress reported success unscheduling BUT wp_next_scheduled() confirmed schedule existance. The database may have rejected the removal.' );
  1573. return false;
  1574. }
  1575. return true;
  1576. } // End unschedule_event().
  1577. } // Emd Class pb_backupbuddy_core.
  1578. ?>