PageRenderTime 42ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/backupbuddy/_importbuddy/_importbuddy.php

https://bitbucket.org/betaimages/chakalos
PHP | 110 lines | 83 code | 17 blank | 10 comment | 36 complexity | f4f6ab1e152c4a03d2a32a1572324f8d MD5 | raw file
Possible License(s): BSD-3-Clause
  1. <?php
  2. $php_minimum = '5.1'; // User's PHP must be equal or newer to this version.
  3. if ( version_compare( PHP_VERSION, $php_minimum ) < 0 ) {
  4. die( 'ERROR #9013. See <a href="http://ithemes.com/codex/page/BackupBuddy:_Error_Codes#9013">this codex page for details</a>. Sorry! PHP version ' . $php_minimum . ' or newer is required for BackupBuddy to properly run. You are running PHP version ' . PHP_VERSION . '.' );
  5. }
  6. define( 'ABSPATH', dirname( __FILE__ ) . '/' );
  7. define( 'PB_BB_VERSION', '#VERSION#' );
  8. define( 'PB_PASSWORD', '#PASSWORD#' );
  9. // Unpack importbuddy files into importbuddy directory.
  10. if ( !file_exists( ABSPATH . 'importbuddy' ) || ( ( count( $_GET ) == 0 ) && ( count( $_POST ) == 0 ) ) ) {
  11. if ( file_exists( ABSPATH . 'importbuddy' ) ) { // Delete importbuddy directory and unpack fresh copy.
  12. echo '<!-- unlinking existing importbuddy directory. -->';
  13. recursive_unlink( ABSPATH . 'importbuddy' );
  14. }
  15. unpack_importbuddy();
  16. }
  17. date_default_timezone_set( @date_default_timezone_get() ); // Prevents date() from throwing a warning if the default timezone has not been set.
  18. if ( isset( $_GET['api'] ) && ( $_GET['api'] != '' ) ) { // API ACCESS
  19. if ( $_GET['api'] == 'ping' ) {
  20. die( 'pong' );
  21. } else {
  22. die( 'Unknown API access action.' );
  23. }
  24. } else { // NORMAL ACCESS.
  25. if ( !file_exists( ABSPATH . 'importbuddy/init.php' ) ) {
  26. die( 'Error: Unable to load importbuddy. Make sure that you downloaded this script from within BackupBuddy. Copying importbuddy files from inside the plugin directory is not sufficient as many file additions are made on demand.' );
  27. } else {
  28. require_once( ABSPATH . 'importbuddy/init.php' );
  29. }
  30. }
  31. function recursive_unlink( $path ) {
  32. return is_file($path)?
  33. @unlink($path):
  34. array_map('recursive_unlink',glob($path.'/*'))==@rmdir($path);
  35. }
  36. /**
  37. * unpack_importbuddy()
  38. *
  39. * Unpacks required files encoded in importbuddy.php into stand-alone files.
  40. *
  41. * @return null
  42. */
  43. function unpack_importbuddy() {
  44. if ( !is_writable( ABSPATH ) ) {
  45. echo 'Error #224834. This directory is not write enabled. Please verify write permissions to continue.';
  46. die();
  47. } else {
  48. $unpack_file = '';
  49. // Make sure the file is complete and contains all the packed data to the end.
  50. if ( false === strpos( file_get_contents( ABSPATH . 'importbuddy.php' ), '###PACKDATA' . ',END' ) ) { // Concat here so we don't false positive on this line when searching.
  51. die( 'ERROR: It appears your importbuddy.php file is incomplete. It may have not finished uploaded completely. Please try re-downloading the script from within BackupBuddy in WordPress (do not just copy the file from the plugin directory) and re-uploading it.' );
  52. }
  53. $handle = @fopen( ABSPATH . 'importbuddy.php', 'r' );
  54. if ( $handle ) {
  55. while ( ( $buffer = fgets( $handle ) ) !== false ) {
  56. if ( substr( $buffer, 0, 11 ) == '###PACKDATA' ) {
  57. $packdata_commands = explode( ',', trim( $buffer ) );
  58. array_shift( $packdata_commands );
  59. if ( $packdata_commands[0] == 'BEGIN' ) {
  60. // Start packed data.
  61. } elseif ( $packdata_commands[0] == 'FILE_START' ) {
  62. $unpack_file = $packdata_commands[2];
  63. } elseif ( $packdata_commands[0] == 'FILE_END' ) {
  64. $unpack_file = '';
  65. } elseif ( $packdata_commands[0] == 'END' ) {
  66. return;
  67. }
  68. } else {
  69. if ( $unpack_file != '' ) {
  70. if ( !is_dir( dirname( ABSPATH . $unpack_file ) ) ) {
  71. $mkdir_result = mkdir( dirname( ABSPATH . $unpack_file ), 0777, true ); // second param makes recursive.
  72. if ( $mkdir_result === false ) {
  73. echo 'Error #54455. Unable to mkdir `' . dirname( ABSPATH . $unpack_file ) . '`<br>';
  74. }
  75. }
  76. $fileput_result = file_put_contents( ABSPATH . $unpack_file, trim( base64_decode( $buffer ) ) );
  77. if ( $fileput_result === false ) {
  78. echo 'Error #65656. Unable to put file contents to `' . ABSPATH . $unpack_file . '`.<br>';
  79. }
  80. }
  81. }
  82. }
  83. if ( !feof( $handle ) ) {
  84. echo "Error: unexpected fgets() fail.<br>";
  85. }
  86. fclose( $handle );
  87. } else {
  88. echo 'ERROR #54455: Unable to open importbuddy.php file for reading in packaged data.<br>';
  89. }
  90. }
  91. }
  92. die();
  93. ?>