PageRenderTime 40ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-content/plugins/backupbuddy/_importbuddy/importbuddy/controllers/pages/1.php

https://bitbucket.org/betaimages/chakalos
PHP | 163 lines | 101 code | 34 blank | 28 comment | 32 complexity | bd1aebc6737a78f1100a842c35a62e62 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. <?php
  2. pb_backupbuddy::set_greedy_script_limits( true );
  3. /**
  4. * upload()
  5. *
  6. * Processes uploaded backup file.
  7. *
  8. * @return array True on upload success; false otherwise.
  9. */
  10. function upload() {
  11. if ( isset( $_POST['upload'] ) && ( $_POST['upload'] == 'local' ) ) {
  12. if ( pb_backupbuddy::$options['password'] != '#PASSWORD#' ) {
  13. $path_parts = pathinfo( $_FILES['file']['name'] );
  14. if ( ( strtolower( substr( $_FILES['file']['name'], 0, 6 ) ) == 'backup' ) && ( strtolower( $path_parts['extension'] ) == 'zip' ) ) {
  15. if ( move_uploaded_file( $_FILES['file']['tmp_name'], basename( $_FILES['file']['name'] ) ) ) {
  16. pb_backupbuddy::alert( 'File Uploaded. Your backup was successfully uploaded.' );
  17. return true;
  18. } else {
  19. pb_backupbuddy::alert( 'Sorry, there was a problem uploading your file.', true );
  20. return false;
  21. }
  22. } else {
  23. pb_backupbuddy::alert( 'Only properly named BackupBuddy zip archives with a zip extension may be uploaded.', true );
  24. return false;
  25. }
  26. } else {
  27. pb_backupbuddy::alert( 'Upload Access Denied. To prevent unauthorized file uploads an importbuddy password must be configured and properly entered to use this feature.' );
  28. return false;
  29. }
  30. }
  31. // DOWNLOAD FILE FROM STASH TO LOCAL.
  32. if ( pb_backupbuddy::_POST( 'upload' ) == 'stash' ) {
  33. /*
  34. echo '<pre>';
  35. print_r( $_POST );
  36. echo '</pre>';
  37. */
  38. $requestcore_file = dirname( dirname( dirname( __FILE__ ) ) ) . '/lib/requestcore/requestcore.class.php';
  39. require_once( $requestcore_file );
  40. $link = pb_backupbuddy::_POST( 'link' );
  41. $destination_file = dirname( dirname( dirname( dirname( __FILE__ ) ) ) ) . '/' . basename( pb_backupbuddy::_POST( 'link' ) );
  42. $destination_file = substr( $destination_file, 0, stripos( $destination_file, '.zip' ) + 4 );
  43. $_GET['file'] = basename( $destination_file );
  44. $request = new RequestCore( $link );
  45. $request->set_write_file( $destination_file );
  46. echo '<div id="pb_importbuddy_working" style="padding: 20px;">Downloading backup from Stash to `' . $destination_file . '`...<br><br><img src="' . pb_backupbuddy::plugin_url() . '/images/loading_large.gif" title="Working... Please wait as this may take a moment..."><br><br></div>';
  47. flush();
  48. $response = $request->send_request( false );
  49. if ( $response !== true ) {
  50. pb_backupbuddy::alert( 'Error #8548459598. Unable to download file from Stash. You may manually download it and upload to the server via FTP.' );
  51. } else { // No error.
  52. if ( ! file_exists( $destination_file ) ) {
  53. pb_backupbuddy::alert( 'Error #34845745878. Stash returned a success but the backup file was not found locally. Check this server\'s directory write permissions. You may manually download it and upload to the server via FTP.' );
  54. }
  55. }
  56. echo '<script type="text/javascript">jQuery("#pb_importbuddy_working").hide();</script>';
  57. }
  58. }
  59. /**
  60. * get_archives_list()
  61. *
  62. * Returns an array of backup archive zip filenames found.
  63. *
  64. * @return array Array of .zip filenames; path NOT included.
  65. */
  66. function get_archives_list() {
  67. if ( !isset( pb_backupbuddy::$classes['zipbuddy'] ) ) {
  68. require_once( pb_backupbuddy::plugin_path() . '/lib/zipbuddy/zipbuddy.php' );
  69. pb_backupbuddy::$classes['zipbuddy'] = new pluginbuddy_zipbuddy( ABSPATH );
  70. }
  71. // List backup files in this directory.
  72. $backup_archives = array();
  73. $backup_archives_glob = glob( ABSPATH . 'backup*.zip' );
  74. if ( !is_array( $backup_archives_glob ) || empty( $backup_archives_glob ) ) { // On failure glob() returns false or an empty array depending on server settings so normalize here.
  75. $backup_archives_glob = array();
  76. }
  77. foreach( $backup_archives_glob as $backup_archive ) {
  78. $comment = pb_backupbuddy::$classes['zipbuddy']->get_comment( $backup_archive );
  79. if ( $comment === false ) {
  80. $comment = '';
  81. }
  82. $this_archive = array(
  83. 'file' => basename( $backup_archive ),
  84. 'comment' => $comment,
  85. );
  86. $backup_archives[] = $this_archive;
  87. }
  88. unset( $backup_archives_glob );
  89. return $backup_archives;
  90. }
  91. /**
  92. * wordpress_exists()
  93. *
  94. * Notifies the user with an alert if WordPress appears to already exist in this directory.
  95. *
  96. * @return boolean True if WordPress already exists; false otherwise.
  97. */
  98. function wordpress_exists() {
  99. if ( file_exists( ABSPATH . 'wp-config.php' ) ) {
  100. return true;
  101. } else {
  102. return false;
  103. }
  104. }
  105. function phpini_exists() {
  106. return file_exists( ABSPATH . 'php.ini' );
  107. }
  108. function htaccess_exists() {
  109. return file_exists( ABSPATH . '.htaccess' );
  110. }
  111. function index_exists() {
  112. if ( file_exists( ABSPATH . 'index.htm' ) === true ) {
  113. return true;
  114. }
  115. if ( file_exists( ABSPATH . 'index.html' ) === true ) {
  116. return true;
  117. }
  118. }
  119. if ( $mode == 'html' ) {
  120. pb_backupbuddy::load_view( 'html_1' );
  121. } else { // API mode.
  122. if ( wordpress_exists() === true ) {
  123. }
  124. if ( phpini_exists() === true ) {
  125. }
  126. if ( htaccess_exists() === true ) {
  127. }
  128. }
  129. ?>