diff -r de56132c008d -r bdac73ed481e install/includes/stages/database_mysql.php --- a/install/includes/stages/database_mysql.php Sun Mar 28 21:49:26 2010 -0400 +++ b/install/includes/stages/database_mysql.php Sun Mar 28 23:10:46 2010 -0400 @@ -14,203 +14,203 @@ */ if ( !defined('IN_ENANO_INSTALL') ) - die(); + die(); if ( isset($_POST['_cont']) ) { - $allow_go = true; - // Do we have everything? If so, continue with installation. - foreach ( array('db_host', 'db_port', 'db_name', 'db_user', 'db_pass') as $field ) - { - if ( empty($_POST[$field]) ) - { - $allow_go = false; - } - } - if ( $allow_go ) - { - require( ENANO_ROOT . '/install/includes/stages/database_post.php' ); - return true; - } + $allow_go = true; + // Do we have everything? If so, continue with installation. + foreach ( array('db_host', 'db_port', 'db_name', 'db_user', 'db_pass') as $field ) + { + if ( empty($_POST[$field]) ) + { + $allow_go = false; + } + } + if ( $allow_go ) + { + require( ENANO_ROOT . '/install/includes/stages/database_post.php' ); + return true; + } } if ( isset($_POST['ajax_test']) ) { - // Test the database connection - $return = array( - 'can_install' => 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' - ))); - } - - if ( preg_match('/^:/', $info['db_host']) && !@file_exists(substr($info['db_host'], 1)) ) - { - $return['host_good'] = false; - echo enano_json_encode($return); - exit(); - } - - if ( $info['db_host'] == 'localhost' && !empty($info['db_port']) && $info['db_port'] != 3306 ) - $info['db_host'] = '127.0.0.1'; - - $dbhost = ( preg_match('/^:/', $info['db_host']) ) ? $info['db_host'] : "{$info['db_host']}:{$info['db_port']}"; - - // Try to connect as the normal user - $test = @mysql_connect($dbhost, $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($dbhost, $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($dbhost, $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(); + // Test the database connection + $return = array( + 'can_install' => 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' + ))); + } + + if ( preg_match('/^:/', $info['db_host']) && !@file_exists(substr($info['db_host'], 1)) ) + { + $return['host_good'] = false; + echo enano_json_encode($return); + exit(); + } + + if ( $info['db_host'] == 'localhost' && !empty($info['db_port']) && $info['db_port'] != 3306 ) + $info['db_host'] = '127.0.0.1'; + + $dbhost = ( preg_match('/^:/', $info['db_host']) ) ? $info['db_host'] : "{$info['db_host']}:{$info['db_port']}"; + + // Try to connect as the normal user + $test = @mysql_connect($dbhost, $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($dbhost, $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($dbhost, $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(''); @@ -219,7 +219,7 @@ ?>
- MySQL logo + MySQL logo

get('dbmysql_blurb_needdb'); ?>

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

'; + echo '

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

'; } ?> @@ -402,144 +402,144 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
-

get('dbmysql_table_title'); ?>

-
- get('dbmysql_field_hostname_title'); ?> -
get('dbmysql_field_hostname_body'); ?> -
-
- - - Good/bad icon -
- get('dbmysql_field_port_title'); ?> -
get('dbmysql_field_port_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('dbmysql_table_title'); ?>

+
+ get('dbmysql_field_hostname_title'); ?> +
get('dbmysql_field_hostname_body'); ?> +
+
+ + + Good/bad icon +
+ get('dbmysql_field_port_title'); ?> +
get('dbmysql_field_port_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'); ?> -

-
+ + +

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

+