. /** * @package MantisBT * @copyright Copyright (C) 2000 - 2002 Kenzaburo Ito - kenito@300baud.org * @copyright Copyright (C) 2002 - 2014 MantisBT Team - mantisbt-dev@lists.sourceforge.net * @link http://www.mantisbt.org */ error_reporting( E_ALL ); /** @todo put this somewhere */ @set_time_limit( 0 ); $g_skip_open_db = true; # don't open the database in database_api.php define( 'MANTIS_INSTALLER', true ); define( 'PLUGINS_DISABLED', true ); require_once( dirname( dirname( __FILE__ ) ) . DIRECTORY_SEPARATOR . 'core.php' ); require_once( 'install_functions.php' ); require_once( 'install_helper_functions.php' ); $g_error_send_page_header = false; # bypass page headers in error handler $g_failed = false; $g_database_upgrade = false; # ------- # print test result function print_test_result( $p_result, $p_hard_fail = true, $p_message = '' ) { global $g_failed; echo 'BAD'; } else { echo 'bgcolor="pink">POSSIBLE PROBLEM'; } if( '' != $p_message ) { echo '
' . $p_message; } } if( GOOD == $p_result ) { echo 'bgcolor="green">GOOD'; } echo ''; } # ------- # print test header and result function print_test( $p_test_description, $p_result, $p_hard_fail = true, $p_message = '' ) { echo "\n$p_test_description"; print_test_result( $p_result, $p_hard_fail, $p_message ); echo "\n"; } # install_state # 0 = no checks done # 1 = server ok, get database information # 2 = check the database information # 3 = install the database # 4 = get additional config file information # 5 = write the config file # 6 = post install checks # 7 = done, link to login or db updater $t_install_state = gpc_get_int( 'install', 0 ); ?> MantisBT Administration - Installation


= 5.3, please use mssqlnative instead' ); } } $g_db = ADONewConnection( $f_db_type ); $t_result = @$g_db->Connect( $f_hostname, $f_db_username, $f_db_password, $f_database_name ); if( $g_db->IsConnected() ) { $g_db_connected = true; } $t_cur_version = config_get( 'database_version', -1 ); if( $t_cur_version > 1 ) { $g_database_upgrade = true; $f_db_exists = true; } else { if( 0 == $t_install_state ) { print_test( 'Config File Exists but Database does not', false, false, 'Bad config_inc.php?' ); } } } else { # read control variables with defaults $f_hostname = gpc_get( 'hostname', config_get( 'hostname', 'localhost' ) ); $f_db_type = gpc_get( 'db_type', config_get( 'db_type', '' ) ); $f_database_name = gpc_get( 'database_name', config_get( 'database_name', 'bugtrack' ) ); $f_db_username = gpc_get( 'db_username', config_get( 'db_username', '' ) ); $f_db_password = gpc_get( 'db_password', config_get( 'db_password', '' ) ); if( CONFIGURED_PASSWORD == $f_db_password ) { $f_db_password = config_get( 'db_password' ); } } $f_admin_username = gpc_get( 'admin_username', '' ); $f_admin_password = gpc_get( 'admin_password', '' ); $f_log_queries = gpc_get_bool( 'log_queries', false ); $f_db_exists = gpc_get_bool( 'db_exists', false ); $f_db_schema = ''; if( $f_db_type == 'db2' ) { # If schema name is supplied, then separate it from database name. if( strpos( $f_database_name, '/' ) != false ) { $f_db2AS400 = $f_database_name; list( $f_database_name, $f_db_schema ) = explode( '/', $f_db2AS400, 2 ); } } if( 0 == $t_install_state ) { ?>
Checking Installation
Setting Admin Username Setting Admin Password Attempting to connect to database as admin Connect( $f_hostname, $f_admin_username, $f_admin_password ); if( $t_result ) { # check if db exists for the admin $t_result = @$g_db->Connect( $f_hostname, $f_admin_username, $f_admin_password, $f_database_name ); if( $t_result ) { $t_db_open = true; $f_db_exists = true; } if( $f_db_type == 'db2' ) { $result = &$g_db->execute( 'set schema ' . $f_db_schema ); if( $result === false ) { print_test_result( BAD, true, 'set schema failed: ' . $g_db->errorMsg() ); } } else { print_test_result( GOOD ); } } else { print_test_result( BAD, true, 'Does administrative user have access to the database? ( ' . db_error_msg() . ' )' ); } ?> Attempting to connect to database as user Connect( $f_hostname, $f_db_username, $f_db_password, $f_database_name ); if( $t_result == true ) { $t_db_open = true; if( $f_db_type == 'db2' ) { $result = &$g_db->execute( 'set schema ' . $f_db_schema ); if( $result === false ) { print_test_result( BAD, true, 'set schema failed: ' . $g_db->errorMsg() ); } } else { print_test_result( GOOD ); } } else { print_test_result( BAD, false, 'Database user doesn\'t have access to the database ( ' . db_error_msg() . ' )' ); } ?> Checking Database Server Version ServerInfo(); echo '
Running ' . string_attribute( $f_db_type ) . ' version ' . $t_version_info['description']; ?>
Type of Database
Hostname (for Database Server)
Username (for Database)
Password (for Database) ">
Database name (for Database)
Admin Username (to if required)
Admin Password (to if required)
Print SQL Queries instead of Writing to the Database >
Attempt Installation
Connect( $f_hostname, $f_admin_username, $f_admin_password, $f_database_name ); if( $f_db_type == 'db2' ) { $rs = $g_db->Execute( "select * from SYSIBM.SCHEMATA WHERE SCHEMA_NAME = '" . $f_db_schema . "' AND SCHEMA_OWNER = '" . $f_db_username . "'" ); if( $rs === false ) { echo "
false"; } if( $rs->EOF ) { $t_result = false; echo $g_db->errorMsg(); } else { $t_result = &$g_db->execute( 'set schema ' . $f_db_schema ); } } $t_db_open = false; if( $t_result == true ) { print_test_result( GOOD ); $t_db_open = true; } else { // create db $g_db = ADONewConnection( $f_db_type ); $t_result = $g_db->Connect( $f_hostname, $f_admin_username, $f_admin_password ); $dict = NewDataDictionary( $g_db ); if( $f_db_type == 'db2' ) { $rs = &$g_db->Execute( "CREATE SCHEMA " . $f_db_schema ); if( !$rs ) { $t_result = false; print_test_result( BAD, true, 'Does administrative user have access to create the database? ( ' . db_error_msg() . ' )' ); $t_install_state--; # db creation failed, allow user to re-enter user/password info } else { print_test_result( GOOD ); $t_db_open = true; } } else { $sqlarray = $dict->CreateDatabase( $f_database_name, Array( 'mysql' => 'DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci' ) ); $ret = $dict->ExecuteSQLArray( $sqlarray, false ); if( $ret == 2 ) { print_test_result( GOOD ); $t_db_open = true; } else { $t_error = db_error_msg(); if( strstr( $t_error, 'atabase exists' ) ) { print_test_result( BAD, false, 'Database already exists? ( ' . db_error_msg() . ' )' ); } else { print_test_result( BAD, true, 'Does administrative user have access to create the database? ( ' . db_error_msg() . ' )' ); $t_install_state--; # db creation failed, allow user to re-enter user/password info } } } } ?> Close(); ?> Connect( $f_hostname, $f_db_username, $f_db_password, $f_database_name ); if( $f_db_type == 'db2' ) { $result = &$g_db->execute( 'set schema ' . $f_db_schema ); if( $result === false ) { echo $g_db->errorMsg(); } } if( $t_result == true ) { print_test_result( GOOD ); } else { print_test_result( BAD, false, 'Database user doesn\'t have access to the database ( ' . db_error_msg() . ' )' ); } $g_db->Close(); ?> Connect( $f_hostname, $f_admin_username, $f_admin_password, $f_database_name ); if( !$f_log_queries ) { $g_db_connected = true; # fake out database access routines used by config_get } $t_last_update = config_get( 'database_version', -1, ALL_USERS, ALL_PROJECTS ); $lastid = count( $upgrade ) - 1; $i = $t_last_update + 1; if( $f_log_queries ) { echo ''; if( $t_sql ) { $ret = $dict->ExecuteSQLArray( $sqlarray, false ); } else { if( isset( $sqlarray[1] ) ) { $ret = call_user_func( 'install_' . $sqlarray[0], $sqlarray[1] ); } else { $ret = call_user_func( 'install_' . $sqlarray[0] ); } } if( $ret == 2 ) { print_test_result( GOOD ); config_set( 'database_version', $i ); } else { $all_sql = ''; foreach ( $sqlarray as $single_sql ) $all_sql .= $single_sql . '
'; print_test_result( BAD, true, $all_sql . $g_db->ErrorMsg() ); } echo ''; } $i++; } if( $f_log_queries ) { # add a query to set the database version echo 'INSERT INTO ' . db_get_table( 'mantis_config_table' ) . ' ( value, type, access_reqd, config_id, project_id, user_id ) VALUES (\'' . $lastid . '\', 1, 90, \'database_version\', 0, 0 );' . "\r\n"; echo '

Your database has not been created yet. Please create the database, then install the tables and data using the information above before proceeding.'; } } if( false == $g_failed ) { $t_install_state++; } else { $t_install_state--; } ?>

Installing Database
Create database if it does not exist
Attempting to connect to database as user
Database Creation Suppressed, SQL Queries follow
';
		}

		# Make sure we do the upgrades using UTF-8 if needed
		if ( $f_db_type === 'mysql' || $f_db_type === 'mysqli' ) {
			$g_db->execute( 'SET NAMES UTF8' );
		}

		if( $f_db_type == 'db2' ) {
			$result = &$g_db->execute( 'set schema ' . $f_db_schema );
			if( $result === false ) {
				echo $g_db->errorMsg();
			}
		}

		while(( $i <= $lastid ) && !$g_failed ) {
			if( !$f_log_queries ) {
				echo '
'; } $dict = NewDataDictionary( $g_db ); $t_sql = true; $t_target = $upgrade[$i][1][0]; if( $upgrade[$i][0] == 'InsertData' ) { $sqlarray = call_user_func_array( $upgrade[$i][0], $upgrade[$i][1] ); } else if( $upgrade[$i][0] == 'UpdateSQL' ) { $sqlarray = array( $upgrade[$i][1], ); $t_target = $upgrade[$i][1]; } else if( $upgrade[$i][0] == 'UpdateFunction' ) { $sqlarray = array( $upgrade[$i][1], ); if( isset( $upgrade[$i][2] ) ) { $sqlarray[] = $upgrade[$i][2]; } $t_sql = false; $t_target = $upgrade[$i][1]; } else { /* 0: function to call, 1: function params, 2: function to evaluate before calling upgrade, if false, skip upgrade. */ if( isset( $upgrade[$i][2] ) ) { if( call_user_func_array( $upgrade[$i][2][0], $upgrade[$i][2][1] ) ) { $sqlarray = call_user_func_array( Array( $dict, $upgrade[$i][0] ), $upgrade[$i][1] ); } else { $sqlarray = array(); } } else { $sqlarray = call_user_func_array( Array( $dict, $upgrade[$i][0] ), $upgrade[$i][1] ); } } if( $f_log_queries ) { if( $t_sql ) { foreach( $sqlarray as $sql ) { echo htmlentities( $sql ) . ";\r\n\r\n"; } } } else { echo 'Schema ' . $upgrade[$i][0] . ' ( ' . $t_target . ' )
# rather than the following line */ $t_install_state++; } # end install_state == 4 # all checks have passed, install the database if( 5 == $t_install_state ) { $t_config_filename = $g_absolute_path . 'config_inc.php'; $t_config_exists = file_exists( $t_config_filename ); ?>
Write Configuration File(s)
Please add the following lines to 'config_inc.php' before continuing:
Connect( $f_hostname, $f_db_username, $f_db_password, $f_database_name ); if( $t_result == true ) { print_test_result( GOOD ); } else { print_test_result( BAD, false, 'Database user doesn\'t have access to the database ( ' . db_error_msg() . ' )' ); } if( $f_db_type == 'db2' ) { $result = &$g_db->execute( 'set schema ' . $f_db_schema ); if( $result === false ) { echo $g_db->errorMsg(); } } ?> Execute( $t_query ); if( $t_result != false ) { print_test_result( GOOD ); } else { print_test_result( BAD, true, 'Database user doesn\'t have SELECT access to the database ( ' . db_error_msg() . ' )' ); } ?> Execute( $t_query ); if( $t_result != false ) { print_test_result( GOOD ); } else { print_test_result( BAD, true, 'Database user doesn\'t have INSERT access to the database ( ' . db_error_msg() . ' )' ); } ?> Execute( $t_query ); if( $t_result != false ) { print_test_result( GOOD ); } else { print_test_result( BAD, true, 'Database user doesn\'t have UPDATE access to the database ( ' . db_error_msg() . ' )' ); } ?> Execute( $t_query ); if( $t_result != false ) { print_test_result( GOOD ); } else { print_test_result( BAD, true, 'Database user doesn\'t have DELETE access to the database ( ' . db_error_msg() . ' )' ); } ?>
Checking Installation
Attempting to connect to database as user
checking ability to SELECT records
checking ability to INSERT records
checking ability to UPDATE records
checking ability to DELETE records
Please log into Mantis. Please log in as the administrator and create your first project.
Checks Failed
Please correct failed checks