PageRenderTime 34ms CodeModel.GetById 8ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-content/plugins/backupbuddy/_importbuddy/importbuddy/controllers/ajax/mysql_test.php

https://bitbucket.org/betaimages/chakalos
PHP | 109 lines | 83 code | 20 blank | 6 comment | 28 complexity | ac0a81a937c7d0b4a64201dc97c8bc37 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. <?php
  2. $can_connect = false;
  3. $connect_error = 'N/A';
  4. $can_select = false;
  5. $select_error = 'N/A';
  6. $wordpress_exists = false;
  7. $failure_encountered = false;
  8. if ( false === @mysql_connect( $_POST['server'], $_POST['user'], $_POST['pass'] ) ) { // Couldnt connect to server or invalid credentials.
  9. $connect_error = mysql_error();
  10. } else {
  11. $can_connect = true;
  12. if ( false === @mysql_select_db( $_POST['name'] ) ) { //
  13. $can_select = false;
  14. $select_error = mysql_error();
  15. } else {
  16. $can_select = true;
  17. // Check number of tables already existing with this prefix.
  18. $result = mysql_query( "SHOW TABLES LIKE '" . mysql_real_escape_string( str_replace( '_', '\_', $_POST['prefix'] ) ) . "%'" );
  19. if ( mysql_num_rows( $result ) > 0 ) {
  20. $wordpress_exists = true;
  21. } else {
  22. $wordpress_exists = false;
  23. }
  24. unset( $result );
  25. }
  26. }
  27. // CAN CONNECT
  28. echo '1. Logging in to server ... ';
  29. if ( $can_connect === true ) {
  30. echo 'Success<br>';
  31. } else {
  32. echo '<font color=red>Failed</font><br>';
  33. echo '&nbsp;&nbsp;&nbsp;&nbsp;Error: ' . $connect_error . '<br>';
  34. $failure_encountered = true;
  35. }
  36. // CAN ACCESS DATABASE BY NAME
  37. echo '2. Verifying database access & permission … ';
  38. if ( $can_select === true ) {
  39. echo 'Success<br>';
  40. } else {
  41. echo '<font color=red>Failed</font><br>';
  42. echo '&nbsp;&nbsp;&nbsp;&nbsp;Error: ' . $select_error . '<br>';
  43. $failure_encountered = true;
  44. }
  45. // DOES WORDPRESS EXIST?
  46. echo '3. Verifying no existing WP data ... ';
  47. if ( $failure_encountered === true ) {
  48. echo 'N/A<br>';
  49. } else {
  50. if ( $wordpress_exists !== true ) { // No existing WordPress.
  51. echo 'Success<br>';
  52. } else { // WordPress exists.
  53. if ( $_POST['wipe_database'] == '1' ) { // Option to wipe JUST MATCHING THIS PREFIX enabled.
  54. echo '<font color=red>Warning</font><br>';
  55. echo '&nbsp;&nbsp;&nbsp;&nbsp;WordPress already exists in this database with this prefix.<br>';
  56. echo '&nbsp;&nbsp;&nbsp;&nbsp;Tables with matching prefix will be wiped prior to import. Use caution.<br>';
  57. } else { // Not wiping. We have an error.
  58. if ( pb_backupbuddy::$options['ignore_sql_errors'] != false ) {
  59. echo '<font color=red>Warning</font><br>';
  60. echo '&nbsp;&nbsp;&nbsp;&nbsp;Option set to ignore existing tables. Use caution.<br>';
  61. } else {
  62. if ( $_POST['wipe_database_all'] == '1' ) { // Option to wipe ALL TABLES enabled.
  63. echo '&nbsp;&nbsp;&nbsp;&nbsp;Warning: WordPress already exists in this database with this prefix.<br>';
  64. } else {
  65. echo '&nbsp;&nbsp;&nbsp;&nbsp;Error: WordPress already exists in this database with this prefix.<br>';
  66. $failure_encountered = true;
  67. }
  68. }
  69. }
  70. }
  71. }
  72. if ( $_POST['wipe_database_all'] == '1' ) { // Option to wipe ALL TABLES enabled.
  73. echo '<font color=red>Warning</font>';
  74. echo ' - <b>ALL TABLES</b> (based on settings) will be wiped prior to import. Use caution.<br>';
  75. }
  76. // Prefix only has allowed chars check.
  77. if ( !preg_match('/^[a-z0-9_]+$/i', $_POST['prefix'] ) ) {
  78. echo '<font color=red>Warning: Prefix contains characters that are not allowed.</font><br>';
  79. $failure_encountered = true;
  80. }
  81. // OVERALL RESULT
  82. echo '4. Overall mySQL test result ... ';
  83. if ( $failure_encountered !== true ) {
  84. echo 'Success';
  85. } else {
  86. echo '<font color=red>Failed</font><br>';
  87. }
  88. die();
  89. ?>