PageRenderTime 27ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/plugins/backupbuddy2/destinations/stash2/_configure.php

https://gitlab.com/mattswann/launch-housing
PHP | 304 lines | 254 code | 42 blank | 8 comment | 43 complexity | 3e4bbe6f28c2617eb3f9704494c93cba MD5 | raw file
  1. <?php // Settings to display in a form for a user to configure.
  2. /*
  3. Pre-populated variables coming into this script:
  4. $destination_settings
  5. $mode
  6. */
  7. if ( isset( $destination['disabled'] ) && ( '1' == $destination['disabled'] ) ) {
  8. die( __( 'This destination is currently disabled based on its settings. Re-enable it under its Advanced Settings.', 'it-l10n-backupbuddy' ) );
  9. }
  10. global $pb_hide_test, $pb_hide_save;
  11. $pb_hide_test = false;
  12. $itxapi_username = '';
  13. $itxapi_password = '';
  14. $itxapi_token = '';
  15. if ( $mode == 'add' ) { // ADD MODE.
  16. $credentials_form = new pb_backupbuddy_settings( 'pre_settings', false, 'action=pb_backupbuddy_backupbuddy&function=destination_picker&quickstart=' . htmlentities( pb_backupbuddy::_GET( 'quickstart' ) ) . '&add=' . htmlentities( pb_backupbuddy::_GET( 'add' ) ) . '&callback_data=' . htmlentities( pb_backupbuddy::_GET( 'callback_data' ) ) . '&sending=' . pb_backupbuddy::_GET( 'sending' ) . '&selecting=' . pb_backupbuddy::_GET( 'selecting' ) ); // name, savepoint|false, additional querystring
  17. $credentials_form->add_setting( array(
  18. 'type' => 'text',
  19. 'name' => 'itxapi_username',
  20. 'title' => __( 'iThemes username', 'it-l10n-backupbuddy' ),
  21. 'tip' => __( '[Example: kerfuffle] - Your iThemes.com membership username.', 'it-l10n-backupbuddy' ),
  22. 'rules' => 'required|string[1-45]',
  23. ) );
  24. $credentials_form->add_setting( array(
  25. 'type' => 'password',
  26. 'name' => 'itxapi_password_raw',
  27. 'title' => __( 'iThemes password', 'it-l10n-backupbuddy' ),
  28. 'tip' => __( '[Example: 48dsds!s08K%x2s] - Your iThemes.com membership password.', 'it-l10n-backupbuddy' ),
  29. 'rules' => 'required|string[1-250]',
  30. ) );
  31. $settings_result = $credentials_form->process();
  32. $login_welcome = __( 'Log in with your iThemes.com member account to begin.', 'it-l10n-backupbuddy' );
  33. if ( count( $settings_result ) == 0 ) { // No form submitted.
  34. echo $login_welcome;
  35. $credentials_form->display_settings( 'Submit' );
  36. $pb_hide_test = true;
  37. $pb_hide_save = true;
  38. return;
  39. } else { // Form submitted.
  40. if ( count( $settings_result['errors'] ) > 0 ) { // Form errors.
  41. echo $login_welcome;
  42. pb_backupbuddy::alert( implode( '<br>', $settings_result['errors'] ) );
  43. $credentials_form->display_settings( 'Submit' );
  44. $pb_hide_test = true;
  45. $pb_hide_save = true;
  46. return;
  47. } else { // No form errors; process!
  48. $pb_hide_test = true;
  49. $pb_hide_save = true;
  50. require_once( dirname( __FILE__ ) . '/class.itx_helper2.php' );
  51. global $wp_version;
  52. $itxapi_username = strtolower( $settings_result['data']['itxapi_username'] );
  53. $password_hash = iThemes_Credentials::get_password_hash( $itxapi_username, $settings_result['data']['itxapi_password_raw'] );
  54. $access_token = ITXAPI_Helper2::get_access_token( $itxapi_username, $password_hash, site_url(), $wp_version );
  55. $settings = array(
  56. 'itxapi_username' => $itxapi_username,
  57. 'itxapi_password' => $access_token,
  58. );
  59. $response = pb_backupbuddy_destination_stash2::stashAPI( $settings, 'connect' );
  60. if ( ! is_array( $response ) ) { // Error message.
  61. pb_backupbuddy::alert( 'Error #23333: Unexpected server response. Check your login and try again. Detailed response: `' . print_r( $response, true ) .'`.' );
  62. $credentials_form->display_settings( 'Submit' );
  63. } else {
  64. if ( isset( $response['error'] ) ) {
  65. pb_backupbuddy::alert( 'Error: ' . $response['error']['message'] );
  66. $credentials_form->display_settings( 'Submit' );
  67. } else {
  68. if ( isset( $response['token'] ) ) {
  69. $itxapi_token = $response['token'];
  70. } else {
  71. pb_backupbuddy::alert( 'Error #382383232: Unexpected server response. Token missing. Check your login and try again. Detailed response: `' . print_r( $response, true ) .'`.' );
  72. $credentials_form->display_settings( 'Submit' );
  73. }
  74. }
  75. }
  76. }
  77. } // end form submitted.
  78. } elseif ( $mode == 'edit' ) { // EDIT MODE.
  79. $settings = array(
  80. 'itxapi_username' => $itxapi_username,
  81. 'itxapi_token' => $itxapi_token,
  82. );
  83. $account_info = pb_backupbuddy_destination_stash2::get_quota( $settings );
  84. $itxapi_username = $destination_settings['itxapi_username'];
  85. }
  86. if ( ( $mode == 'save' ) || ( $mode == 'edit' ) || ( $itxapi_token != '' ) ) {
  87. $default_name = NULL;
  88. if ( ( $mode != 'save' ) && ( 'edit' != $mode ) ) {
  89. $settings = array(
  90. 'itxapi_username' => $itxapi_username,
  91. 'itxapi_token' => $itxapi_token,
  92. );
  93. $account_info = pb_backupbuddy_destination_stash2::get_quota( $settings );
  94. if ( ! is_array( $account_info ) ) {
  95. $pb_hide_test = true;
  96. $pb_hide_save = true;
  97. return false;
  98. } else {
  99. $pb_hide_test = false;
  100. $pb_hide_save = false;
  101. }
  102. $account_details = 'Welcome to your BackupBuddy Stash, <b>' . $itxapi_username . '</b>. Your account is ';
  103. if ( $account_info['subscriber_locked'] == '1' ) {
  104. $account_details .= 'LOCKED';
  105. } elseif ( $account_info['subscriber_expired'] == '1' ) {
  106. $account_details .= 'EXPIRED';
  107. } elseif ( $account_info['subscriber_active'] == '1' ) {
  108. $account_details .= 'active';
  109. } else {
  110. $account_details .= 'Unknown';
  111. }
  112. $account_details .= '.';
  113. if ( $mode == 'add' ) {
  114. $default_name = 'My Stash (v2)';
  115. echo $account_details;
  116. //echo '<br>';
  117. echo ' ' . __( 'To jump right in using the defaults just hit "Add Destination" below.', 'it-l10n-backupbuddy' );
  118. } else {
  119. echo '<div style="text-align: center;">' . $account_details . '</div>';
  120. }
  121. if ( $mode == 'add' ) {
  122. // Check to see if user already has a Stash with this username set up for this site. No need for multiple same account Stashes.
  123. foreach( (array)pb_backupbuddy::$options['remote_destinations'] as $destination ) {
  124. if ( ( isset( $destination['itxapi_username'] ) ) && ( strtolower( $destination['itxapi_username'] ) == strtolower( $itxapi_username ) ) ) {
  125. echo '<br><br>';
  126. pb_backupbuddy::alert( 'Note: You already have a Stash destination set up under the provided iThemes account username. It is unnecessary to create multiple Stash destinations that go to the same user account as they are effectively the same destination and a duplicate.' );
  127. break;
  128. }
  129. }
  130. }
  131. echo '<br><br>';
  132. echo pb_backupbuddy_destination_stash2::get_quota_bar( $account_info );
  133. echo '<!-- STASH DETAILS: ' . print_r( $account_info, true ) . ' -->';
  134. } // end if NOT in save mode.
  135. // Form settings.
  136. $settings_form->add_setting( array(
  137. 'type' => 'text',
  138. 'name' => 'title',
  139. 'title' => __( 'Destination name', 'it-l10n-backupbuddy' ),
  140. 'tip' => __( 'Name of the new destination to create. This is for your convenience only.', 'it-l10n-backupbuddy' ),
  141. 'rules' => 'required|string[1-45]',
  142. 'default' => $default_name,
  143. ) );
  144. $settings_form->add_setting( array(
  145. 'type' => 'text',
  146. 'name' => 'full_archive_limit',
  147. 'title' => __( 'Full backup limit', 'it-l10n-backupbuddy' ),
  148. 'tip' => __( '[Example: 5] - Enter 0 for no limit. This is the maximum number of Full (complete) backup archives to be stored in this specific destination. If this limit is met the oldest backup of this type will be deleted.', 'it-l10n-backupbuddy' ),
  149. 'rules' => 'int[0-9999999]',
  150. 'css' => 'width: 50px;',
  151. 'after' => ' backups. &nbsp;<span class="description">0 or blank for no limit.</span>',
  152. ) );
  153. $settings_form->add_setting( array(
  154. 'type' => 'text',
  155. 'name' => 'db_archive_limit',
  156. 'title' => __( 'Database only limit', 'it-l10n-backupbuddy' ),
  157. 'tip' => __( '[Example: 5] - Enter 0 for no limit. This is the maximum number of Database Only backup archives to be stored in this specific destination. If this limit is met the oldest backup of this type will be deleted.', 'it-l10n-backupbuddy' ),
  158. 'rules' => 'int[0-9999999]',
  159. 'css' => 'width: 50px;',
  160. 'after' => ' backups. &nbsp;<span class="description">0 or blank for no limit.</span>',
  161. ) );
  162. $settings_form->add_setting( array(
  163. 'type' => 'text',
  164. 'name' => 'files_archive_limit',
  165. 'title' => __( 'Files only limit', 'it-l10n-backupbuddy' ),
  166. 'tip' => __( '[Example: 5] - Enter 0 for no limit. This is the maximum number of Files Only backup archives to be stored in this specific destination. If this limit is met the oldest backup of this type will be deleted.', 'it-l10n-backupbuddy' ),
  167. 'rules' => 'int[0-9999999]',
  168. 'css' => 'width: 50px;',
  169. 'after' => ' backups. &nbsp;<span class="description">0 or blank for no limit.</span>',
  170. ) );
  171. $settings_form->add_setting( array(
  172. 'type' => 'title',
  173. 'name' => 'advanced_begin',
  174. 'title' => '<span class="dashicons dashicons-arrow-right"></span> ' . __( 'Advanced Options', 'it-l10n-backupbuddy' ),
  175. 'row_class' => 'advanced-toggle-title',
  176. ) );
  177. $settings_form->add_setting( array(
  178. 'type' => 'text',
  179. 'name' => 'max_burst',
  180. 'title' => __( 'Send per burst', 'it-l10n-backupbuddy' ),
  181. 'tip' => __( '[Example: 10] - This is the amount of data that will be sent per burst within a single PHP page load/chunk. Bursts happen within a single page load. Chunks occur when broken up between page loads/PHP instances. Reduce if hitting PHP memory limits. Chunking time limits will only be checked between bursts. Lower burst size if timeouts occur before chunking checks trigger.', 'it-l10n-backupbuddy' ),
  182. 'rules' => 'required|int[0-9999999]',
  183. 'css' => 'width: 50px;',
  184. 'after' => ' MB',
  185. 'row_class' => 'advanced-toggle',
  186. ) );
  187. $settings_form->add_setting( array(
  188. 'type' => 'text',
  189. 'name' => 'max_time',
  190. 'title' => __( 'Max time per chunk', 'it-l10n-backupbuddy' ),
  191. 'tip' => __( '[Example: 30] - Enter 0 for no limit (aka no chunking; bursts may still occur based on burst size setting). This is the maximum number of seconds per page load that bursts will occur. If this time is exceeded when a burst finishes then the next burst will be chunked and ran on a new page load. Multiple bursts may be sent within each chunk.', 'it-l10n-backupbuddy' ),
  192. 'rules' => '',
  193. 'css' => 'width: 50px;',
  194. 'after' => ' secs. <span class="description">' . __( 'Blank for detected default:', 'it-l10n-backupbuddy' ) . ' ' . backupbuddy_core::detectMaxExecutionTime() . ' sec</span>',
  195. 'row_class' => 'advanced-toggle',
  196. ) );
  197. $settings_form->add_setting( array(
  198. 'type' => 'checkbox',
  199. 'name' => 'ssl',
  200. 'options' => array( 'unchecked' => '0', 'checked' => '1' ),
  201. 'title' => __( 'Encrypt connection', 'it-l10n-backupbuddy' ) . '*',
  202. 'tip' => __( '[Default: enabled] - When enabled, all transfers will be encrypted with SSL encryption. Disabling this may aid in connection troubles but results in lessened security. Note: Once your files arrive on our server they are encrypted using AES256 encryption. They are automatically decrypted upon download as needed.', 'it-l10n-backupbuddy' ),
  203. 'css' => '',
  204. 'after' => '<span class="description"> ' . __('Enable connecting over SSL.', 'it-l10n-backupbuddy' ) . '<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;* Files are always encrypted with AES256 upon arrival.</span>',
  205. 'rules' => '',
  206. 'row_class' => 'advanced-toggle',
  207. ) );
  208. $settings_form->add_setting( array(
  209. 'type' => 'checkbox',
  210. 'name' => 'use_packaged_cert',
  211. 'options' => array( 'unchecked' => '0', 'checked' => '1' ),
  212. 'title' => __( 'Use included CA bundle', 'it-l10n-backupbuddy' ),
  213. 'tip' => __( '[Default: disabled] - When enabled, BackupBuddy will use its own bundled SSL certificate bundle for connecting to the server. Use this if SSL fails due to SSL certificate issues with your server.', 'it-l10n-backupbuddy' ),
  214. 'css' => '',
  215. 'after' => '<span class="description"> ' . __('Use included certificate bundle.', 'it-l10n-backupbuddy' ) . '</span>',
  216. 'rules' => '',
  217. 'row_class' => 'advanced-toggle',
  218. ) );
  219. if ( $mode !== 'edit' ) {
  220. $settings_form->add_setting( array(
  221. 'type' => 'checkbox',
  222. 'name' => 'manage_all_files',
  223. 'options' => array( 'unchecked' => '0', 'checked' => '1' ),
  224. 'title' => __( 'Manage all files', 'it-l10n-backupbuddy' ),
  225. 'tip' => __( '[Default: enabled] - When enabled, you have access to manage and view all files stored in your Stash account. You will be prompted for your password to access backups for sites other than this one. If disabled the option is entirely removed for added security. For example, you may wish to disable this feature if a client has access and you want to keep them away from your files. This option can NOT be changed without deleting and re-creating the Stash destination for added security.', 'it-l10n-backupbuddy' ),
  226. 'css' => '',
  227. 'rules' => '',
  228. 'row_class' => 'advanced-toggle',
  229. ) );
  230. $settings_form->add_setting( array(
  231. 'type' => 'checkbox',
  232. 'name' => 'disable_file_management',
  233. 'options' => array( 'unchecked' => '0', 'checked' => '1' ),
  234. 'title' => __( 'Disable file management', 'it-l10n-backupbuddy' ),
  235. 'tip' => __( '[Default: unchecked] - When checked, selecting this destination disables browsing or accessing files stored at this destination from within BackupBuddy.', 'it-l10n-backupbuddy' ),
  236. 'css' => '',
  237. 'rules' => '',
  238. 'row_class' => 'advanced-toggle',
  239. ) );
  240. }
  241. $settings_form->add_setting( array(
  242. 'type' => 'checkbox',
  243. 'name' => 'disabled',
  244. 'options' => array( 'unchecked' => '0', 'checked' => '1' ),
  245. 'title' => __( 'Disable destination', 'it-l10n-backupbuddy' ),
  246. 'tip' => __( '[Default: unchecked] - When checked, this destination will be disabled and unusable until re-enabled. Use this if you need to temporary turn a destination off but don\t want to delete it.', 'it-l10n-backupbuddy' ),
  247. 'css' => '',
  248. 'after' => '<span class="description"> ' . __('Check to disable this destination until re-enabled.', 'it-l10n-backupbuddy' ) . '</span>',
  249. 'rules' => '',
  250. 'row_class' => 'advanced-toggle',
  251. ) );
  252. $settings_form->add_setting( array(
  253. 'type' => 'hidden',
  254. 'name' => 'itxapi_username',
  255. 'default' => $itxapi_username,
  256. ) );
  257. $settings_form->add_setting( array(
  258. 'type' => 'hidden',
  259. 'name' => 'itxapi_token',
  260. 'default' => $itxapi_token,
  261. ) );
  262. }