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

/wp-content/plugins/backupbuddy/_serverbuddy/serverbuddy/controllers/pages/1.php

https://bitbucket.org/summitds/bloomsburgpa.org
PHP | 161 lines | 101 code | 31 blank | 29 comment | 32 complexity | 83dc7ad657831b40121fcc1e23b7ddd3 MD5 | raw file
Possible License(s): GPL-2.0, AGPL-1.0, BSD-3-Clause, GPL-3.0, LGPL-2.1
  1. <?php
  2. // Removed Jan 15, 2013 Dustin - 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. pb_backupbuddy::set_greedy_script_limits( true );
  34. /*
  35. echo '<pre>';
  36. print_r( $_POST );
  37. echo '</pre>';
  38. */
  39. $requestcore_file = dirname( dirname( dirname( __FILE__ ) ) ) . '/lib/requestcore/requestcore.class.php';
  40. require_once( $requestcore_file );
  41. $link = pb_backupbuddy::_POST( 'link' );
  42. $destination_file = dirname( dirname( dirname( dirname( __FILE__ ) ) ) ) . '/' . basename( pb_backupbuddy::_POST( 'link' ) );
  43. $destination_file = substr( $destination_file, 0, stripos( $destination_file, '.zip' ) + 4 );
  44. $_GET['file'] = basename( $destination_file );
  45. $request = new RequestCore( $link );
  46. $request->set_write_file( $destination_file );
  47. 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>';
  48. flush();
  49. $response = $request->send_request( false );
  50. if ( $response !== true ) {
  51. pb_backupbuddy::alert( 'Error #8548459598. Unable to download file from Stash. You may manually download it and upload to the server via FTP.' );
  52. } else { // No error.
  53. if ( ! file_exists( $destination_file ) ) {
  54. 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.' );
  55. }
  56. }
  57. echo '<script type="text/javascript">jQuery("#pb_importbuddy_working").hide();</script>';
  58. }
  59. }
  60. /**
  61. * get_archives_list()
  62. *
  63. * Returns an array of backup archive zip filenames found.
  64. *
  65. * @return array Array of .zip filenames; path NOT included.
  66. */
  67. function get_archives_list() {
  68. if ( !isset( pb_backupbuddy::$classes['zipbuddy'] ) ) {
  69. require_once( pb_backupbuddy::plugin_path() . '/lib/zipbuddy/zipbuddy.php' );
  70. pb_backupbuddy::$classes['zipbuddy'] = new pluginbuddy_zipbuddy( ABSPATH );
  71. }
  72. // List backup files in this directory.
  73. $backup_archives = array();
  74. $backup_archives_glob = glob( ABSPATH . 'backup*.zip' );
  75. 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.
  76. $backup_archives_glob = array();
  77. }
  78. foreach( $backup_archives_glob as $backup_archive ) {
  79. $comment = pb_backupbuddy::$classes['zipbuddy']->get_comment( $backup_archive );
  80. if ( $comment === false ) {
  81. $comment = '';
  82. }
  83. $this_archive = array(
  84. 'file' => basename( $backup_archive ),
  85. 'comment' => $comment,
  86. );
  87. $backup_archives[] = $this_archive;
  88. }
  89. unset( $backup_archives_glob );
  90. return $backup_archives;
  91. }
  92. /**
  93. * wordpress_exists()
  94. *
  95. * Notifies the user with an alert if WordPress appears to already exist in this directory.
  96. *
  97. * @return boolean True if WordPress already exists; false otherwise.
  98. */
  99. function wordpress_exists() {
  100. if ( file_exists( ABSPATH . 'wp-config.php' ) ) {
  101. return true;
  102. } else {
  103. return false;
  104. }
  105. }
  106. function phpini_exists() {
  107. return file_exists( ABSPATH . 'php.ini' );
  108. }
  109. function htaccess_exists() {
  110. return file_exists( ABSPATH . '.htaccess' );
  111. }
  112. function index_exists() {
  113. if ( file_exists( ABSPATH . 'index.htm' ) === true ) {
  114. return true;
  115. }
  116. if ( file_exists( ABSPATH . 'index.html' ) === true ) {
  117. return true;
  118. }
  119. }
  120. if ( $mode == 'html' ) {
  121. pb_backupbuddy::load_view( 'html_1' );
  122. } else { // API mode.
  123. if ( wordpress_exists() === true ) {
  124. }
  125. if ( phpini_exists() === true ) {
  126. }
  127. if ( htaccess_exists() === true ) {
  128. }
  129. }
  130. ?>