diff -r 299a90e28abc -r 87e08a6e4fec install/includes/stages/database_mysql.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/install/includes/stages/database_mysql.php Wed Jan 16 13:55:49 2008 -0500 @@ -0,0 +1,508 @@ + false, + 'host_good' => true, + 'creating_user' => false, + 'db_exist' => false, + 'creating_db' => false, + 'creating_db_grant' => false, + 'root_fail' => false, + 'version' => array( + 'version' => 'unknown', + 'good' => 'indeterminate' + ), + 'last_error' => '' + ); + + if ( !isset($_POST['info']) ) + die(); + + $info = $_POST['info']; + + // From here on out will be JSON responses + header('Content-type: application/json'); + + try + { + $info = @enano_json_decode($info); + } + catch ( Zend_Json_Exception $e ) + { + die(enano_json_encode(array( + 'mode' => 'error', + 'error' => 'Exception in JSON decoder' + ))); + } + + // Try to connect as the normal user + $test = @mysql_connect($info['db_host'], $info['db_user'], $info['db_pass']); + if ( !$test ) + { + $return['creating_user'] = true; + $return['last_error'] = mysql_error(); + if ( strstr( $return['last_error'], 'Lost connection' ) || strstr( $return['last_error'], 'Unknown MySQL server host' ) ) + { + $return['host_good'] = false; + } + // Doing that failed. If we have root credentials, test those + if ( !empty($info['db_root_user']) && !empty($info['db_root_pass']) ) + { + // Log in with root rights and if that works, tell 'em we'll reset the password or create + // the account if it doesn't exist already. This is done with GRANT ALL PRIVILEGES ON enano_db.* + // etc etc, a little hackish but known to work with MySQL >= 4.1. + $test_root = @mysql_connect($info['db_host'], $info['db_root_user'], $info['db_root_pass']); + if ( $test_root ) + { + // We logged in with root rights, assume that we have appropriate permissions. + // If not, well, the installation will fail. Tough on the user, but creating + // test databases/users is too risky. + + // Does the database exist? + $q = @mysql_query('USE `' . mysql_real_escape_string($info['db_name']) . '`;', $test_root); + if ( !$q ) + { + // Nope, we'll have to create it + $return['creating_db'] = true; + $return['last_error'] = mysql_error(); + } + + $version = mysql_get_server_info($test_root); + $return['version'] = array( + 'version' => $version, + 'good' => version_compare($version, '4.0.17', '>=') + ); + + $return['can_install'] = ( $return['version']['good'] ) ? true : false; + } + else + { + // Well that helped. Root credentials are bad. + $return['creating_db'] = true; + $return['root_fail'] = true; + } + } + else + { + // No root credentials, fail out + $return['root_fail'] = true; + } + } + else + { + // We're connected; do we have permission to use the database? + $have_database = false; + $q = @mysql_query('USE `' . mysql_real_escape_string($info['db_name']) . '`;', $test); + if ( $q ) + { + // Permissions are good and we're all connected. Perform version check... + $version = mysql_get_server_info($test); + $return['version'] = array( + 'version' => $version, + 'good' => version_compare($version, '4.0.17', '>=') + ); + + $return['can_install'] = ( $return['version']['good'] ) ? true : false; + } + else + { + $return['last_error'] = mysql_error(); + $return['creating_db'] = true; + + // We don't have permission to use the database or it doesn't exist. + // See if we have a root login to work with, if not then fail + if ( !empty($info['db_root_user']) && !empty($info['db_root_pass']) ) + { + // Log in with root rights and if that works, tell 'em we'll create the database. + $test_root = @mysql_connect($info['db_host'], $info['db_root_user'], $info['db_root_pass']); + if ( $test_root ) + { + // We logged in with root rights, assume that we have appropriate permissions. + // If not, well, the installation will fail. Tough on the user, but creating + // test databases/users is too risky. + + // See if the database already exists + $dbname = mysql_real_escape_string($info['db_name']); + $q = @mysql_query("SHOW DATABASES LIKE '$dbname';", $test_root); + if ( $q ) + { + if ( mysql_num_rows($q) > 0 ) + { + $return['creating_db'] = false; + $return['creating_db_grant'] = true; + } + @mysql_free_result($q); + } + + $version = mysql_get_server_info($test); + $return['version'] = array( + 'version' => $version, + 'good' => version_compare($version, '4.0.17', '>=') + ); + + $return['can_install'] = ( $return['version']['good'] ) ? true : false; + } + else + { + // Well that helped. Root credentials are bad. + $return['creating_db'] = true; + $return['root_fail'] = true; + } + } + // No root credentials, fail out + } + } + + if ( isset($test) && @is_resource($test) ) + @mysql_close($test); + + if ( isset($test_root) && @is_resource($test_root) ) + @mysql_close($test_root); + + echo enano_json_encode($return); + + exit(); +} + +$ui->add_header(''); +$ui->show_header(); + +?> + +
+ MySQL logo +
+ +

get('dbmysql_blurb_needdb'); ?>

+

get('dbmysql_blurb_howtomysql'); ?>

+ + ' . $lang->get('database_vm_login_info', array( 'host' => 'localhost', 'user' => 'enano', 'pass' => 'clurichaun', 'name' => 'enano_www1' )) . ' +

'; +} +?> + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+

get('dbmysql_table_title'); ?>

+
+ get('dbmysql_field_hostname_title'); ?> +
get('dbmysql_field_hostname_body'); ?> +
+
+ + + Good/bad icon +
+ get('dbmysql_field_dbname_title'); ?>
+ get('dbmysql_field_dbname_body'); ?>
+ +
+ + + Good/bad icon +
+ get('dbmysql_field_dbauth_title'); ?>
+ get('dbmysql_field_dbauth_body'); ?>
+ +
+
+
+ +
+ Good/bad icon +
+

get('database_heading_optionalinfo'); ?>

+
+ get('dbmysql_field_tableprefix_title'); ?>
+ get('dbmysql_field_tableprefix_body'); ?> +
+ + + Good/bad icon +
+ get('dbmysql_field_rootauth_title'); ?>
+ get('dbmysql_field_rootauth_body'); ?>
+ +
+
+
+ +
+ Good/bad icon +
+ get('dbmysql_field_mysqlversion_title'); ?> + + get('dbmysql_field_mysqlversion_blurb_willbechecked'); ?> + + Good/bad icon +
+ get('dbmysql_field_droptables_title'); ?>
+ get('dbmysql_field_droptables_body'); ?> +
+ +
+ +
+
+ + + + + + +
+ + +

+ get('meta_lbl_before_continue'); ?>
+ • get('database_objective_test'); ?>
+ • get('database_objective_uncrypt'); ?> +

+
+ +
+ + +