CVE-2022-4446 (Unknown, published 2022-12-13T12:15Z)
Description: value: PHP Remote File Inclusion in GitHub repository tsolucio/corebos prior to 8.0.
Severity: nan (CVSS v3 base score: 9.8)
Weakness: CWE-669 \u2014 Incorrect Resource Transfer Between Spheres
The product does not properly transfer a resource/behavior to another sphere, or improperly imports a resource/behavior from another sphere, in a manner that provides unintended control over that resource.
Repository: https://github.com/tsolucio/corebos
Files changed:
Commit message: chore(Migration) delete obsolete migration files


Vulnerable code:
<?php
/*+*******************************************************************************
 *  The contents of this file are subject to the vtiger CRM Public License Version 1.0
 * ("License"); You may not use this file except in compliance with the License
 * The Original Code is:  vtiger CRM Open Source
 * The Initial Developer of the Original Code is vtiger.
 * Portions created by vtiger are Copyright (C) vtiger.
 * All Rights Reserved.
 *********************************************************************************/

@include_once 'install/config.db.php';
global $dbconfig, $vtiger_current_version, $vtconfig, $coreBOS_app_version;

$hostname = $_SERVER['SERVER_NAME'];
$web_root = ($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST']:$_SERVER['SERVER_NAME'].':'.$_SERVER['SERVER_PORT'];
$web_root .= $_SERVER['REQUEST_URI'];
$web_root = str_replace('/install.php', '', $web_root);
$web_root = $_SERVER['REQUEST_SCHEME'].'://'.$web_root;

$current_dir = pathinfo(dirname(__FILE__));
$current_dir = $current_dir['dirname'].'/';
$cache_dir = 'cache/';

session_start();

$host_name = !isset($_REQUEST['hostName']) ? $dbconfig['db_server'].':'.$dbconfig['db_port'] : $_REQUEST['hostName'];
$demoData = !isset($_REQUEST['demoData']) ? $vtconfig['demoData'] : $_REQUEST['demoData'];
$currencyName = !isset($_REQUEST['currencyName']) ? preg_replace('/\s+$/', '', $vtconfig['currencyName']) : $_REQUEST['currencyName'];
$adminEmail = !isset($_REQUEST['adminEmail']) ? $vtconfig['adminEmail'] : $_REQUEST['adminEmail'];
$adminPwd = !isset($_REQUEST['adminPwd']) ? $vtconfig['adminPwd'] : $_REQUEST['adminPwd'];
$standarduserEmail = !isset($_REQUEST['standarduserEmail']) ? $vtconfig['standarduserEmail'] : $_REQUEST['standarduserEmail'];
$standarduserPwd = !isset($_REQUEST['standarduserPwd']) ? $vtconfig['standarduserPwd'] : $_REQUEST['standarduserPwd'];
$dbUsername = !isset($_REQUEST['dbUsername']) ? $dbconfig['db_username'] : $_REQUEST['dbUsername'];
$dbPassword = !isset($_REQUEST['dbPassword']) ? $dbconfig['db_password'] : $_REQUEST['dbPassword'];
$dbType = !isset($_REQUEST['dbType']) ? $dbconfig['db_type'] : $_REQUEST['dbType'];
$dbName = !isset($_REQUEST['dbName']) ? $dbconfig['db_name'] : $_REQUEST['dbName'];

session_start();
$create_db = (isset($_REQUEST['check_createdb']) && $_REQUEST['check_createdb'] == 'on');

$_SESSION['config_file_info']['db_hostname'] = $host_name;
$_SESSION['config_file_info']['db_username'] = $dbUsername;
$_SESSION['config_file_info']['db_password'] = $dbPassword;
$_SESSION['config_file_info']['db_name'] = $dbName;
$_SESSION['config_file_info']['db_type'] = $dbType;
$_SESSION['config_file_info']['site_URL']= $web_root;
$_SESSION['config_file_info']['root_directory'] = $current_dir;
$_SESSION['config_file_info']['currency_name'] = $currencyName;
$_SESSION['config_file_info']['admin_email'] = $adminEmail;

$_SESSION['installation_info']['currency_name'] = $currencyName;
$_SESSION['installation_info']['check_createdb'] = $create_db;
if (!isset($_REQUEST['root_user'])) {
	$_SESSION['installation_info']['root_user'] = $dbUsername;
} else {
	$_SESSION['installation_info']['root_user'] = $_REQUEST['root_user'];
}
if (!isset($_REQUEST['root_password'])) {
	$_SESSION['installation_info']['root_password'] = $dbPassword;
} else {
	$_SESSION['installation_info']['root_password'] = $_REQUEST['root_password'];
}
$_SESSION['installation_info']['admin_email']= $adminEmail;
$_SESSION['installation_info']['admin_password'] = $adminPwd;
$_SESSION['installation_info']['standarduser_email']= $standarduserEmail;
$_SESSION['installation_info']['standarduser_password'] = $standarduserPwd;

if (isset($_REQUEST['create_utf8_db'])) {
	$_SESSION['installation_info']['create_utf8_db'] = 'true';
} else {
	$_SESSION['installation_info']['create_utf8_db'] = 'false';
}
$_SESSION['config_file_info']['vt_charset']= 'UTF-8';

if (isset($_REQUEST['db_populate'])) {
	$_SESSION['installation_info']['db_populate'] = 'true';
} else {
	$_SESSION['installation_info']['db_populate'] = ($demoData == '1')? 'true': 'false';
}
require_once 'modules/Utilities/Currencies.php';
if (isset($currencyName)) {
	$_SESSION['installation_info']['currency_code'] = $currencies[$currencyName][0];
	$_SESSION['installation_info']['currency_symbol'] = $currencies[$currencyName][1];
}
require 'install/CreateTables.php';
?>
<?php
/*+*******************************************************************************
 * The contents of this file are subject to the vtiger CRM Public License Version 1.0
 * ("License"); You may not use this file except in compliance with the License
 * The Original Code is:  vtiger CRM Open Source
 * The Initial Developer of the Original Code is vtiger.
 * Portions created by vtiger are Copyright (C) vtiger.
 * All Rights Reserved.
 ********************************************************************************/
session_start();

if (isset($_REQUEST['source_directory'])) {
	$source_directory = $_REQUEST['source_directory'];
	if (!empty($source_directory)) {
		$tmp = strlen($source_directory);
		if ($source_directory[$tmp-1]!= '/' && $source_directory[$tmp-1]!= "\\") {
			$source_directory .= '/';
		}
		$_SESSION['migration_info']['source_directory'] = $source_directory;
	}
} else {
	$source_directory = $_SESSION['migration_info']['source_directory'];
}

if (isset($_REQUEST['root_directory'])) {
	$_SESSION['migration_info']['root_directory'] = $root_directory = $_REQUEST['root_directory'];
} else {
	$root_directory = $_SESSION['migration_info']['root_directory'];
}
if (isset($_REQUEST['user_name'])) {
	$_SESSION['migration_info']['user_name'] = $user_name = $_REQUEST['user_name'];
} else {
	$user_name = $_SESSION['migration_info']['user_name'];
}
if (isset($_REQUEST['user_pwd'])) {
	$_SESSION['migration_info']['user_pwd'] = $user_pwd = $_REQUEST['user_pwd'];
} else {
	$user_pwd = $_SESSION['migration_info']['user_pwd'];
}
if (isset($_REQUEST['old_version'])) {
	$_SESSION['migration_info']['old_version'] = $old_version = $_REQUEST['old_version'];
} else {
	$old_version = $_SESSION['migration_info']['old_version'];
}
if (isset($_REQUEST['new_dbname'])) {
	$_SESSION['migration_info']['new_dbname'] = $new_dbname = $_REQUEST['new_dbname'];
} else {
	$new_dbname = $_SESSION['migration_info']['new_dbname'];
}

$dbVerifyResult = Migration_Utils::verifyMigrationInfo($_SESSION['migration_info']);
$next = $dbVerifyResult['flag'];
$error_msg = $dbVerifyResult['error_msg'];
$error_msg_info = $dbVerifyResult['error_msg_info'];

$oldDbName = $dbVerifyResult['old_dbname'];
$configFileInfo = $dbVerifyResult['config_info'];

$dbType = $configFileInfo['db_type'];
$dbHostName = $configFileInfo['db_hostname'];
$newDbName = $configFileInfo['db_name'];
$configFileUtils = new ConfigFile_Utils($_SESSION['config_file_info']);

if (!$configFileUtils->createConfigFile()) {
	die("<strong class='big'><font color='red'>{$installationStrings['ERR_CANNOT_WRITE_CONFIG_FILE']}</font></strong>");
}
if ($next) {
	$_SESSION['authentication_key'] = md5(microtime());
	$_SESSION['config_file_info'] = $configFileInfo;

	require_once 'install/VerifyDBHealth.php';

	if ($_SESSION[$newDbName.'_'.$dbHostName.'_HealthApproved'] != true || $_SESSION['pre_migration'] != true) {
		header('Location:install.php?file=PreMigrationActions.php');
	} else {
		$innodbEngineCheck = true;
	}
	if ($oldDbName == $newDbName && empty($_REQUEST['forceDbCheck'])) {
		header('Location:install.php?file=PreMigrationActions.php');
	}
}

include 'modules/Migration/versions.php';
?>
<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title><?php echo $installationStrings['APP_NAME']. ' - ' . $installationStrings['LBL_CONFIG_WIZARD']. ' - ' . $installationStrings['LBL_CONFIRM_SETTINGS']?></title>
	<script type="text/javascript" src="include/jquery/jquery.js"></script>
	<script type="text/javascript" src="include/js/vtlib.js"></script>
	<script type="text/javascript" src="include/js/general.js"></script>
	<link href="include/install/install.css" rel="stylesheet" type="text/css">
</head>

<body class="small cwPageBg" topmargin="0" leftmargin="0" marginheight="0" marginwidth="0">

	<br>
	<!-- Table for cfgwiz starts -->

	<table border=0 cellspacing=0 cellpadding=0 width=80% align=center>
	<tr>
		<td class="cwHeadBg" align=left>
			<img src="include/install/images/configwizard.gif" alt="<?php echo $installationStrings['LBL_CONFIG_WIZARD']; ?>" hspace="20" title="<?php echo $installationStrings['LBL_CONFIG_WIZARD']; ?>">
		</td>
		<td class="cwHeadBg1" align=right>
			<img src="include/install/images/app_logo.png" alt="<?php echo $installationStrings['APP_NAME']; ?>" title="<?php echo $installationStrings['APP_NAME']; ?>">
		</td>
		<td class="cwHeadBg1" width=2%></td>
	</tr>
	</table>
	<table border=0 cellspacing=0 cellpadding=0 width=80% align=center>
	<tr>
		<td background="include/install/images/topInnerShadow.gif" colspan=2 align=left>
			<img height="10" src="include/install/images/topInnerShadow.gif" >
		</td>
	</tr>
	</table>
	<table border=0 cellspacing=0 cellpadding=10 width=80% align=center>
		<tr>
			<td class="small" bgcolor="#4572BE" align=center>
				<!-- Master display -->
				<table border=0 cellspacing=0 cellpadding=0 width=97%>
					<tr id="confirmSettingsWindow">
						<td width=80% valign=top class="cwContentDisplay" align=center colspan=2>
							<table width="100%" cellspacing="0" cellpadding="10" border="0">
								<tr>
									<td align="left" colspan="2" class="small paddingTop">
										<span class="bigHeading"><?php echo $installationStrings['LBL_CONFIRM_CONFIG_SETTINGS']; ?></span>
										<br/>
										<hr size="1" noshade=""/>
									</td>
								</tr>
								<?php if ($error_msg) { ?>
								<tr>
									<td align=left class="small" colspan=2 width=50% style="padding-left:10px">
										<div style="background-color:#ff0000;color:#ffffff;padding:5px">
											<b><?php echo $error_msg ?></b>
										</div>
										<?php if ($error_msg_info) { ?>
											<p><?php echo $error_msg_info ?><p>
										<?php } ?>
									</td>
								</tr>
								<?php } ?>
								<tr>
									<td width="80%" align="left" style="padding-left: 10%;" class="small">
										<table width="100%" cellspacing="1" cellpadding="0" border="0" align="center" class="level3">
											<tr>
												<td colspan="2">
													<strong><?php echo $installationStrings['LBL_DATABASE_CONFIGURATION']; ?></strong><hr size="1" noshade=""/>
												</td>
											</tr>
											<tr>
												<td width="40%" nowrap=""><?php echo $installationStrings['LBL_DATABASE_TYPE']; ?></td>
												<td nowrap="" align="left"> <font class="dataInput"><i><?php echo $dbType; ?></i></font></td>
											</tr>
											<tr>
												<td width="40%" nowrap="">
													<?php echo $installationStrings['LBL_OLD']. ' ' .$installationStrings['LBL_DATABASE_NAME']; ?>
												</td>
													<td nowrap="" align="left"> <font class="dataInput"><i><?php echo $oldDbName; ?></i></font></td>
												</tr>
											<tr>
												<td width="40%" nowrap="">
													<?php echo $installationStrings['LBL_NEW']. ' ' .$installationStrings['LBL_DATABASE_NAME']; ?>
												</td>
												<td nowrap="" align="left"> <font class="dataInput"><?php echo $newDbName; ?></font></td>
											</tr>
											<tr>
												<td width="40%" nowrap=""><?php echo $installationStrings['LBL_INNODB_ENGINE_CHECK']; ?></td>
												<td nowrap="" align="left">
													<?php if ($innodbEngineCheck == 1) { ?>
													<font class="dataInput"><?php echo $installationStrings['LBL_FIXED']; ?></font>
													<?php } else { ?>
													<font class="dataInput"><span class="redColor"><?php echo $installationStrings['LBL_NOT_FIXED']; ?></span></font></td>
													<?php } ?>
											</tr>
										</table>
									</td>
								</tr>
								<tr>
									<td width="80%" align="left" style="padding-left: 10%;" class="small">
										<table width="100%" cellspacing="1" cellpadding="0" border="0" align="center" class="level3">
											<tr>
												<td colspan="2">
													<strong><?php echo $installationStrings['LBL_SOURCE_CONFIGURATION']; ?></strong><hr size="1" noshade=""/>
												</td>
											</tr>
											<tr>
												<td width="40%"><?php echo $installationStrings['LBL_PREVIOUS_INSTALLATION_VERSION']; ?></td>
												<td align="left"> <i><?php echo $versions[$old_version]; ?></i></td>
											</tr>
											<tr>
												<td width="40%"><?php echo $installationStrings['LBL_PREVIOUS_INSTALLATION_PATH']; ?></td>
												<td align="left"> <i><?php echo $source_directory; ?></i></td>
											</tr>
											<tr>
												<td width="40%"><?php echo $installationStrings['LBL_NEW_INSTALLATION_PATH']; ?></td>
												<td align="left"> <i><?php echo $root_directory; ?></i></td>
											</tr>
											<tr>
												<td width="40%">Admin <?php echo $installationStrings['LBL_USER_NAME']; ?></td>
												<td align="left"> <i><?php echo $user_name; ?></i></td>
											</tr>
										</table>
									</td>
								</tr>
								<tr>
									<td align="left">
										<form action="install.php" method="post" name="form" id="form">
											<input type="hidden" name="file" value="SetMigrationConfig.php">
											<input type="submit" class="button" value="&#139;&#139;&nbsp;<?php echo $installationStrings['LBL_CHANGE']; ?>" title="<?php echo $installationStrings['LBL_CHANGE']; ?>" />
										</form>
									</td>
									<?php if ($next) { ?>
									<td align="right">
										<form action="install.php" method="post" name="form" id="form">
											<input type="hidden" name="mode" value="migration">
											<input type="hidden" name="file" value="MigrationProcess.php">
											<input type="hidden" name="auth_key" value="<?php echo $_SESSION['authentication_key']; ?>" />
											<input type="submit" class="button" value="<?php echo $installationStrings['LBL_NEXT']; ?>&nbsp;&#155;&#155;" title="<?php echo $installationStrings['LBL_NEXT']; ?>" />
										</form>
									</td>
									<?php } ?>
								</tr>
							</table>
						</td>
					</tr>
				</table>
			</td>
		</tr>
	</table>
	<table border=0 cellspacing=0 cellpadding=0 width=80% align=center>
		<tr>
			<td background="include/install/images/bottomGradient.gif"><img src="include/install/images/bottomGradient.gif"></td>
		</tr>
	</table>
	<table border=0 cellspacing=0 cellpadding=0 width=80% align=center>
		<tr>
			<td align=center><img src="include/install/images/bottomShadow.jpg"></td>
		</tr>
	</table>	
	<table border=0 cellspacing=0 cellpadding=0 width=80% align=center>
		<tr>
			<td class=small align=center> <a href="<?php echo $coreBOS_app_url; ?>" target="_blank"><?php echo $coreBOS_app_name; ?></a></td>
		</tr>
</table>
</body>
</html>
<?php
/*+*******************************************************************************
 * The contents of this file are subject to the vtiger CRM Public License Version 1.0
 * ("License"); You may not use this file except in compliance with the License
 * The Original Code is:  vtiger CRM Open Source
 * The Initial Developer of the Original Code is vtiger.
 * Portions created by vtiger are Copyright (C) vtiger.
 * All Rights Reserved.
 ********************************************************************************/
session_start();
$migrationInfo = $_SESSION['migration_info'];
$root_directory = $migrationInfo['root_directory'];
$source_directory = $migrationInfo['source_directory'];
session_destroy();
?>

<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title><?php echo $installationStrings['APP_NAME']. ' - ' . $installationStrings['LBL_CONFIG_WIZARD']. ' - ' . $installationStrings['LBL_FINISH']?></title>
	<link href="include/install/install.css" rel="stylesheet" type="text/css">
	<link href="themes/softed/style.css" rel="stylesheet" type="text/css">
</head>

<body class="small cwPageBg" topmargin="0" leftmargin="0">
	<br>
	<!-- Table for cfgwiz starts -->
	<table border=0 cellspacing=0 cellpadding=0 width=80% align=center>
		<tr>
			<td class="cwHeadBg" align=left>
				<img src="include/install/images/configwizard.gif" alt="<?php echo $installationStrings['LBL_CONFIG_WIZARD']; ?>" hspace="20" title="<?php echo $installationStrings['LBL_CONFIG_WIZARD']; ?>">
			</td>
			<td class="cwHeadBg1" align=right>
				<img src="include/install/images/app_logo.png" alt="<?php echo $installationStrings['APP_NAME']; ?>" title="<?php echo $installationStrings['APP_NAME']; ?>">
			</td>
			<td class="cwHeadBg1" width=2%></td>
		</tr>
	</table>
	<table border=0 cellspacing=0 cellpadding=0 width=80% align=center>
		<tr>
			<td background="include/install/images/topInnerShadow.gif" align=left><img height="10" src="include/install/images/topInnerShadow.gif" ></td>
		</tr>
	</table>
	<table border=0 cellspacing=0 cellpadding=10 width=80% align=center>
	<tr>
		<td class="small" bgcolor="#4572BE" align=center>
			<!-- Master display -->
			<table border=0 cellspacing=0 cellpadding=0 width=97%>
			<tr>
				<td width=80% valign=top class="cwContentDisplay" align=left>
				<!-- Right side tabs -->
					<table border=0 cellspacing=0 cellpadding=10 width=100%>
					<tr>
						<td align=left class="small paddingTop">
							<span class="bigHeading"><?php echo $installationStrings['LBL_CONFIG_COMPLETED']; ?></span>
							<br>
							<hr noshade size=1>
						</td>
					</tr>
					<tr>
						<td align=center class="small" style="height:250px;">
<?php
$renameResult = Common_Install_Wizard_Utils::renameInstallationFiles();
$renamefile = $renameResult['renamefile'];
$ins_file_renamed = $renameResult['install_file_renamed'];
$ins_dir_renamed = $renameResult['install_directory_renamed'];

$_SESSION['VTIGER_DB_VERSION']= $vtiger_current_version;
?>
	<table border=0 cellspacing=0 cellpadding=5 align="center" width="80%" class="contentDisplay">
		<tr>
			<td align=center class=small>
				<b><?php echo $installationStrings['LBL_MIGRATION_FINISHED'].'. '. $coreBOS_app_url. '-' .$coreBOS_app_version. ' ' .$installationStrings['LBL_ALL_SET_TO_GO']; ?></b>
				<hr noshade size=1>
				<div style="width:100%;padding:10px;" align=left>
					<ul>
						<?php if ($ins_file_renamed) { ?>
						<li><?php echo $installationStrings['LBL_INSTALL_PHP_FILE_RENAMED']. ' ' .$renamefile;?>install.php.txt.</li>
						<?php } else { ?>
						<li><font color='red'><?php echo $installationStrings['WARNING_RENAME_INSTALL_PHP_FILE']; ?>.</font></li>
						<?php } ?>
						
						<?php /*if ($mig_file_renamed) { ?>
						<li><?php echo $installationStrings['LBL_MIGRATE_PHP_FILE_RENAMED']. ' ' .$renamefile;?>migrate.php.txt.</li>
						<?php } else { ?>
						<li><font color='red'><?php echo $installationStrings['WARNING_RENAME_MIGRATE_PHP_FILE']; ?>.</font></li>
						<?php } */ ?>
						<?php if ($ins_dir_renamed) { ?>
						<li><?php echo $installationStrings['LBL_INSTALL_DIRECTORY_RENAMED']. ' ' .$renamefile;?>install.</li> 
						<?php } else { ?>
						<li><font color='red'><?php echo $installationStrings['WARNING_RENAME_INSTALL_DIRECTORY']; ?>.</font></li>
						<?php } ?>
					</ul>
					<br>
					<ul>
						<li><?php echo $installationStrings['LBL_OLD_VERSION_IS_AT'] . $source_directory;?>.
						<li><?php echo $installationStrings['LBL_CURRENT_SOURCE_PATH_IS'] . $root_directory;?>.
						<li><?php echo $installationStrings['LBL_LOGIN_USING_ADMIN']; ?>.</li>
						<li><?php echo $installationStrings['LBL_SET_OUTGOING_EMAIL_SERVER']; ?></li>
						<li><?php echo $installationStrings['LBL_RENAME_HTACCESS_FILE']; ?>. <a href="javascript:void(0);" onclick="showhidediv();"><?php echo $installationStrings['LBL_MORE_INFORMATION']; ?></a>
							<div id='htaccess_div' style="display:none"><br><br>
								<?php echo $installationStrings['MSG_HTACCESS_DETAILS']; ?>
							</div>
						</li>
					</ul>
					<br>
					<ul><strong>
						<li><font color='#0000FF'><?php echo $installationStrings['LBL_YOU_ARE_IMPORTANT']; ?></font></li>
						<li><?php echo $installationStrings['LBL_PRIDE_BEING_ASSOCIATED']; ?></li>
						<li><?php echo $installationStrings['LBL_TALK_TO_US_AT_FORUMS']; ?></li>
						<li><?php echo $installationStrings['LBL_WE_AIM_TO_BE_BEST']. '. ' .$installationStrings['LBL_SPACE_FOR_YOU']; ?></li>
					</strong></ul>
				</div>
			</td>
		</tr>
	</table>
	<br>
	<table border=0 cellspacing=0 cellpadding=10 width=100%>
		<tr>
			<td colspan=2 align="center">
				<form action="index.php" method="post" name="form" id="form">
					<input type="hidden" name="default_user_name" value="admin">
					<input type="submit" class="button" value="<?php echo $installationStrings['LBL_FINISH']; ?>" title="<?php echo $installationStrings['LBL_FINISH']; ?>" />
				</form>
			</td>
		</tr>
	</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>

<table border=0 cellspacing=0 cellpadding=0 width=80% align=center>
	<tr>
		<td background="include/install/images/bottomGradient.gif"><img src="include/install/images/bottomGradient.gif"></td>
	</tr>
</table>
<table border=0 cellspacing=0 cellpadding=0 width=80% align=center>
	<tr>
		<td align=center><img src="include/install/images/bottomShadow.jpg"></td>
	</tr>
</table>
<table border=0 cellspacing=0 cellpadding=0 width=80% align=center>
	<tr>
		<td class=small align=center> <a href="<?php echo $coreBOS_app_url; ?>" target="_blank"><?php echo $coreBOS_app_name; ?></a></td>
	</tr>
</table>
</body>
</html>	
<?php
/*+*******************************************************************************
 *  The contents of this file are subject to the vtiger CRM Public License Version 1.0
 * ("License"); You may not use this file except in compliance with the License
 * The Original Code is:  vtiger CRM Open Source
 * The Initial Developer of the Original Code is vtiger.
 * Portions created by vtiger are Copyright (C) vtiger.
 * All Rights Reserved.
 *
 *********************************************************************************/
session_start();
if ($_SESSION['authentication_key'] != $_REQUEST['auth_key']) {
	die($installationStrings['ERR_NOT_AUTHORIZED_TO_PERFORM_THE_OPERATION']);
}
if (!empty($_REQUEST['rootUserName'])) {
	$_SESSION['migration_info']['root_username'] = $_REQUEST['rootUserName'];
}
if (!empty($_REQUEST['rootPassword'])) {
	$_SESSION['migration_info']['root_password'] = $_REQUEST['rootPassword'];
} else {
	$_SESSION['migration_info']['root_password'] = '';
}

require_once 'include/db_backup/DatabaseBackup.php';
require_once 'include/db_backup/Targets/Response.php';
require_once 'include/db_backup/Targets/Database.php';
require_once 'include/db_backup/Source/MysqlSource.php';
$mode = $_REQUEST['mode'];

$source_directory = $_SESSION['migration_info']['source_directory'];
require_once $source_directory.'config.inc.php';
$createDB = $_REQUEST['createDB'];
if (empty($createDB)) {
	$createDB = false;
} else {
	$createDB = true;
}

$hostName = $dbconfig['db_server'].$dbconfig['db_port'];
$username = $dbconfig['db_username'];
$password = $dbconfig['db_password'];
$dbName = $dbconfig['db_name'];
$sourceConfig = new DatabaseConfig($hostName, $username, $password, $dbName);
$source = new MysqlSource($sourceConfig);
if (strtolower($mode) == 'dump') {
	header('Content-type: text/plain; charset=UTF-8');
	$responseDest = new Response($sourceConfig, true);
	$dbBackup = new DatabaseBackup($source, $responseDest);
	$dbBackup->backup();
} else {
	$targetName = $_REQUEST['newDatabaseName'];
	try {
		if (!empty($targetName) && $dbName != $targetName) {
			$rootUserName = $_SESSION['migration_info']['root_username'];
			$rootPassword = $_SESSION['migration_info']['root_password'];
			$destConfig = new DatabaseConfig($hostName, $username, $password, $targetName, 'mysql', $rootUserName, $rootPassword);
			$databaseDest = new Database($destConfig, $createDB, true);
			$dbBackup = new DatabaseBackup($source, $databaseDest);
			$dbBackup->backup();
			$_SESSION['migration_info']['new_dbname'] = $targetName;
			$_SESSION['config_file_info']['vt_charset'] = 'UTF-8';
			echo 'true';
			return;
		}
		echo 'false';
	} catch (DatabaseBackupException $e) {
		echo 'false';
	} catch (Exception $e) {
		echo 'false';
	}
}
?>
<?php
/*+*******************************************************************************
 * The contents of this file are subject to the vtiger CRM Public License Version 1.0
 * ("License"); You may not use this file except in compliance with the License
 * The Original Code is:  vtiger CRM Open Source
 * The Initial Developer of the Original Code is vtiger.
 * Portions created by vtiger are Copyright (C) vtiger.
 * All Rights Reserved.
 ********************************************************************************/

global $php_max_execution_time;
set_time_limit($php_max_execution_time);

session_start();

$auth_key = $_REQUEST['auth_key'];
if ($_SESSION['authentication_key'] != $auth_key) {
	die($installationStrings['ERR_NOT_AUTHORIZED_TO_PERFORM_THE_OPERATION']);
}

if (isset($_REQUEST['selected_modules'])) {
	$_SESSION['migration_info']['selected_optional_modules'] = $_REQUEST['selected_modules'];
}

Migration_Utils::copyRequiredFiles($_SESSION['migration_info']['source_directory'], $_SESSION['migration_info']['root_directory']);
?>

<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title><?php echo $installationStrings['APP_NAME']. ' - ' . $installationStrings['LBL_CONFIG_WIZARD']. ' - ' . $installationStrings['LBL_MIGRATION']?></title>
	<script type="text/javascript" src="include/jquery/jquery.js"></script>
	<script type="text/javascript" src="include/js/vtlib.js"></script>
	<script type="text/javascript" src="include/js/general.js"></script>
	<link href="themes/softed/style.css" rel="stylesheet" type="text/css">
	<link href="include/install/install.css" rel="stylesheet" type="text/css">
</head>

<?php
if ($_REQUEST['migration_start'] != 'true') {
	?>
	<body class="small cwPageBg" topmargin="0" leftmargin="0" marginheight="0" marginwidth="0">
		<br>
		<!-- Table for cfgwiz starts -->
		<table border=0 cellspacing=0 cellpadding=0 width=80% align=center>
		<tr>
			<td class="cwHeadBg" align=left>
				<img src="include/install/images/configwizard.gif" alt="<?php echo $installationStrings['LBL_CONFIG_WIZARD']; ?>" hspace="20" title="<?php echo $installationStrings['LBL_CONFIG_WIZARD']; ?>">
			</td>
			<td class="cwHeadBg1" align=right>
				<img src="include/install/images/app_logo.png" alt="<?php echo $installationStrings['APP_NAME'];?>" title="<?php echo $installationStrings['APP_NAME'];?>">
			</td>
			<td class="cwHeadBg1" width=2%></td>
		</tr>
		</table>
		<table border=0 cellspacing=0 cellpadding=0 width=80% align=center>
		<tr>
			<td background="include/install/images/topInnerShadow.gif" colspan=2 align=left><img height="10" src="include/install/images/topInnerShadow.gif" ></td>
		</tr>
		</table>
		<table border=0 cellspacing=0 cellpadding=10 width=80% align=center>
			<tr>
				<td class="small" bgcolor="#4572BE" align=center>
					<!-- Master display -->
					<table border=0 cellspacing=0 cellpadding=0 width=97%>
						<tr>
							<td width=80% valign=top class="cwContentDisplay" align=center colspan=2>
							<br>
							</td>
						</tr>
						<tr>
							<td width=80% valign=top class="cwContentDisplay" align=center colspan=2>
							<!-- Right side tabs -->
								<table cellspacing=0 cellpadding=10 width=95% align=center class='level3'>
									<tr>
										<td align=center>
											<iframe class='licence' id='triggermigration_iframe' frameborder=0 src='' marginwidth=20 scrolling='auto'>
											</iframe>
										</td>
									</tr>
								</table>
							</td>
						</tr>
						<tr>
							<td width=80% valign=top class="cwContentDisplay" align=center colspan=2>
							<!-- Right side tabs -->
								<table cellspacing=0 cellpadding=10 width=90% align=center class='cwContentDisplay'>
									<tr>
							<td align=left width=50% valign=top ><br>
							</td>
							<td width=50% valign=top align=right>
											<br>
								<div id='Mig_Close' style='display:none;'>
									<form action="install.php" method="post" name="form" id="form">
										<input type="hidden" name="file" value="MigrationComplete.php" />
										<input type="submit" class="button" value="<?php echo $installationStrings['LBL_NEXT']; ?>&nbsp;&#155;&#155;" title="<?php echo $installationStrings['LBL_NEXT']; ?>" />
									</form>
								</div>
							</td>
									</tr>
								</table>
							</td>
						</tr>
					</table>
				</td>
			</tr>
		</table>
		<table border=0 cellspacing=0 cellpadding=0 width=80% align=center>
		<tr>
			<td background="include/install/images/bottomGradient.gif"><img src="include/install/images/bottomGradient.gif"></td>
		</tr>
		</table>
		<table border=0 cellspacing=0 cellpadding=0 width=80% align=center>
		<tr>
			<td align=center><img src="include/install/images/bottomShadow.jpg"></td>
		</tr>
		</table>
		<table border=0 cellspacing=0 cellpadding=0 width=80% align=center>
			<tr>
			<td class=small align=center> <a href="<?php echo $coreBOS_app_url; ?>" target="_blank"><?php echo $coreBOS_app_name; ?></a></td>
			</tr>
		</table>
		<script type='text/javascript'>
		var auth_key = '<?php echo $auth_key; ?>';
		if(typeof('Event') != 'undefined') {
			jQuery( window ).on('load', function() {
				VtigerJS_DialogBox.progress();
				document.getElementById('triggermigration_iframe').src = 'install.php?file=MigrationProcess.php&migration_start=true&auth_key='+auth_key;
			});
		}
		function Migration_Complete() {
			document.getElementById('Mig_Close').style.display = 'block';
		}
		</script>
		<!-- Prefetch image to display later for Screen blocker -->
		<img style="display: none;" src="include/install/images/loading.gif">
		<img src="themes/softed/images/layerPopupBg.gif" style="display: none;"/>
	<?php
} else {
	// Start the migration now
	echo '<body onload="window.parent.VtigerJS_DialogBox.hideprogress();">';

	require_once 'include/utils/utils.php';
	require_once 'include/logging.php';
	$migrationlog = LoggerManager::getLogger('MIGRATION');

	if ($_SESSION['authentication_key']==$_REQUEST['auth_key']) {
		$completed = Migration_Utils::migrate($_SESSION['migration_info']);
		if ($completed) {
			echo "<script type='text/javascript'>window.parent.Migration_Complete();</script>";
		}
	}
}
?>
	</body>
</html>
<?php
/*+**********************************************************************************
 * The contents of this file are subject to the vtiger CRM Public License Version 1.0
 * ("License"); You may not use this file except in compliance with the License
 * The Original Code is:  vtiger CRM Open Source
 * The Initial Developer of the Original Code is vtiger.
 * Portions created by vtiger are Copyright (C) vtiger.
 * All Rights Reserved.
 ************************************************************************************/
session_start();

require_once 'install/VerifyDBHealth.php';

$migrationInfo = $_SESSION['migration_info'];
$source_directory = $migrationInfo['source_directory'];
require_once $source_directory.'config.inc.php';
$dbHostName = $dbconfig['db_hostname'];
$dbName = $dbconfig['db_name'];

$newDbForCopy = $newDbName = $migrationInfo['new_dbname'];
if ($dbName == $newDbForCopy) {
	$newDbForCopy = '';
}
$_SESSION['pre_migration'] = true;
?>
<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title><?php echo $installationStrings['APP_NAME'].' - '.$installationStrings['LBL_CONFIG_WIZARD'].' - '. $installationStrings['LBL_PRE_MIGRATION_TOOLS']?></title>
	<link href="themes/softed/style.css" rel="stylesheet" type="text/css">
	<link href="include/install/install.css" rel="stylesheet" type="text/css">
	<script type="text/javascript" src="include/js/vtlib.js"></script>
	<script type="text/javascript" src="include/js/general.js"></script>
	<script type="text/javascript" src="include/jquery/jquery.js"></script>
	<script type="text/javascript">
		function fixDBHealth() {
			VtigerJS_DialogBox.progress();
			var value = jQuery('#auth_key').val();
			var url = 'install.php?file=VerifyDBHealth.php&ajax=true&updateTableEngine=true&updateEngineForAllTables=true&auth_key='+value;
			jQuery.post(url,function(data,status) {
				fnvshNrm('responsePopupContainer');
				jQuery('#responsePopupContainer').show();
				var element = jQuery('#responsePopup');
				if (status == 'success') {
					if (trim(data) == 'TABLE_TYPE_FIXED') {
						element.html('<?php echo $installationStrings['MSG_SUCCESSFULLY_FIXED_TABLE_TYPES']; ?>');
						jQuery('#databaseFixMessageDiv').hide();
					} else {
						element.html('<?php echo $installationStrings['ERR_FAILED_TO_FIX_TABLE_TYPES']; ?>');
					}
				} else {
					element.html('<?php echo $installationStrings['ERR_FAILED_TO_FIX_TABLE_TYPES']; ?>');
				}
				jQuery('#dbMirrorCopy').hide();
				VtigerJS_DialogBox.hideprogress();
				placeAtCenter(document.getElementById('responsePopupContainer'));
			});
		}

		function viewDBReport() {
			var value = jQuery('#auth_key').val();
			var url = 'install.php?file=VerifyDBHealth.php&ajax=true&viewDBReport=true&auth_key='+value;
			window.open(url,'DBHealthCheck', 'width=700px, height=500px, resizable=1,menubar=0, location=0, toolbar=0,scrollbars=1');			
		}

		function getDbDump() {
			var value = jQuery('#auth_key').val();
			var url = 'install.php?file=MigrationDbBackup.php&mode=dump&auth_key='+value;
			window.open(url,'DatabaseDump', 'width=800px, height=600px, resizable=1,menubar=0, location=0, toolbar=0,scrollbars=1');
		}

		function doDBCopy() {
			var dbName = jQuery('#newDatabaseName').val();
			if (trim(dbName) == '') {
				alert("<?php echo $installationStrings['ERR_SPECIFY_NEW_DATABASE_NAME']; ?>");
				jQuery('#newDatabaseName').focus();
				return false;
			}
			var rootUserName = jQuery('#rootUserName').val();
			if (trim(rootUserName) == '') {
				alert("<?php echo $installationStrings['ERR_SPECIFY_ROOT_USER_NAME']; ?>");
				jQuery('#rootUserName').focus();
				return false;
			}
			VtigerJS_DialogBox.progress();
			var rootPassword = jQuery('#rootPassword').val();
			var value = jQuery('#auth_key').val();
			var url = 'install.php?file=MigrationDbBackup.php&mode=copy&auth_key='+value;
			url += ('&newDatabaseName='+dbName+'&rootUserName='+rootUserName+'&rootPassword='+rootPassword+'&createDB=true');
			jQuery.post(url,function(data,status) {
				fnvshNrm('responsePopupContainer');
				jQuery('#responsePopupContainer').show();
				var element = jQuery('#responsePopup');
				if(status == 'success'){
					if(data != 'true' && data != true){
						element.html('<?php echo $installationStrings['ERR_DATABASE_COPY_FAILED']; ?>.');
					}else{
						element.html('<?php echo $installationStrings['MSG_DATABASE_COPY_SUCCEDED']; ?>');
					}
				}else{
					element.html('<?php echo $installationStrings['ERR_DATABASE_COPY_FAILED']; ?>.');
				}
				jQuery('#dbMirrorCopy').hide();
				VtigerJS_DialogBox.hideprogress();
				placeAtCenter(document.getElementById('responsePopupContainer'));
			});
		}

		function showCopyPopup() {
			fnvshNrm('dbMirrorCopy');
			jQuery('#dbMirrorCopy').show();
			placeAtCenter(document.getElementById('dbMirrorCopy'));
		}
	</script>
</head>

<body class="small cwPageBg" topmargin="0" leftmargin="0">

	<br>
	<!-- Table for cfgwiz starts -->
	<table border=0 cellspacing=0 cellpadding=0 width=80% align=center>
		<tr>
			<td class="cwHeadBg" align=left>
				<img src="include/install/images/configwizard.gif" alt="<?php echo $installationStrings['LBL_CONFIG_WIZARD']; ?>" hspace="20" title="<?php echo $installationStrings['LBL_CONFIG_WIZARD']; ?>">
			</td>
			<td class="cwHeadBg1" align=right>
				<img src="include/install/images/app_logo.png" alt="<?php echo $installationStrings['APP_NAME']; ?>" title="<?php echo $installationStrings['APP_NAME']; ?>">
			</td>
			<td class="cwHeadBg1" width=2%></td>
		</tr>
	</table>
	<table border=0 cellspacing=0 cellpadding=0 width=80% align=center>
		<tr>
			<td background="include/install/images/topInnerShadow.gif" colspan=2 align=left><img height="10" src="include/install/images/topInnerShadow.gif" ></td>
		</tr>
	</table>
	<table border=0 cellspacing=0 cellpadding=10 width=80% align=center>
		<tr>
			<td class="small" bgcolor="#4572BE" align=center>
				<!-- Master display -->
				<table border=0 cellspacing=0 cellpadding=0 width=97%>
					<tr>
						<td width=80% valign=top class="cwContentDisplay" align=center>
						<!-- Right side tabs -->
							<table cellspacing=5 cellpadding=2 width=95% align=center>
								<tr>
									<td align="left" colspan="2" class="small paddingTop">
										<span class="bigHeading"><?php echo $installationStrings['LBL_PRE_MIGRATION_TOOLS']; ?></span>
										<br/>
										<hr size="1" noshade=""/>
									</td>
								</tr>
								<?php if ($_SESSION[$newDbName.'_'.$dbHostName.'_HealthApproved'] != true) { ?>
								<tr>
									<td colspan=2>
										<div id="databaseFixMessageDiv" class="helpmessagebox paddingPoint5em smallFont" align="left">
											<span class="redColor fontBold"><?php echo $installationStrings['LBL_IMPORTANT']; ?>:</span>
											<hr />
											<?php echo $installationStrings['ERR_TABLES_NOT_INNODB'].'. '.$installationStrings['MSG_CHANGE_ENGINE_BEFORE_MIGRATION']; ?>.
											<br/>
											<br />
											<a href="javascript:void(0)" onclick="fixDBHealth();"><?php echo $installationStrings['LBL_FIX_NOW']; ?></a>&nbsp; | &nbsp;<a href="javascript:void(0)" onclick="viewDBReport();"><?php echo $installationStrings['LBL_VIEW_REPORT']; ?></a>
										</div>
									</td>
								</tr>
								<?php } ?>
								<tr>
									<td colspan=2>
										<table cellpadding="0" cellspacing="1" align=right width="100%" class="level3">
											<tr >
												<td align=left width=50% valign=top>
													<table cellpadding="5" cellspacing="1" align=right width="100%" border="0">
														<tr>
															<td width="48%" align="left">
																<table width="100%" cellspacing="0" cellpadding="5" border="0">
																	<tr>
																		<td width="50" valign="top" rowspan="2">
																			<input type="image" src="include/install/images/dbDump.gif" alt="<?php echo $installationStrings['LBL_DB_DUMP_DOWNLOAD']; ?>" border="0" title="<?php echo $installationStrings['LBL_DB_DUMP_DOWNLOAD']; ?>" onClick="getDbDump();">
																		</td>
																		<td valign="bottom" class="heading2"><?php echo $installationStrings['LBL_DATABASE_BACKUP']; ?></td>
																	</tr>
																	<tr>
																		<td valign="top" class="mediumLineHeight">
																			<b><?php echo $installationStrings['QUESTION_NOT_TAKEN_BACKUP_YET']; ?></b><br>
																			<?php echo $installationStrings['LBL_CLICK_FOR_DUMP_AND_SAVE']; ?>.<br><br>
																			<div class="helpmessagebox"><b><?php echo $installationStrings['LBL_NOTE']; ?></b>:<br><?php echo $installationStrings['MSG_PROCESS_TAKES_LONGER_TIME_BASED_ON_DB_SIZE']; ?>.</div>
																		</td>
																	</tr>
																</table>
															</td>
															<td height="100%" width="2%" style="border-left:2px dotted #999999;"></td>
															<td width="48%" align="left">
																<table width="100%" cellspacing="0" cellpadding="5" border="0">
																	<tr>
																		<td width="50" valign="top" rowspan="2">
																			<input type="image" src="include/install/images/dbCopy.gif" alt="<?php echo $installationStrings['LBL_DB_COPY']; ?>" border="0" title="<?php echo $installationStrings['LBL_DB_COPY']; ?>" onClick="showCopyPopup();">
																		</td>
																		<td valign="bottom" class="heading2"><?php echo $installationStrings['LBL_DATABASE_COPY']; ?></td>
																	</tr>
																	<tr>
																		<td valign="top" class="mediumLineHeight">
																			<b><?php echo $installationStrings['QUESTION_MIGRATING_TO_NEW_DB']; ?>?</b><br>
																			<?php echo $installationStrings['LBL_CLICK_FOR_NEW_DATABASE']; ?>.
																			<br><br>
																			<div class="helpmessagebox"><b><?php echo $installationStrings['LBL_RECOMMENDED']; ?></b>:<br>
																				<?php echo $installationStrings['MSG_USE_OTHER_TOOLS_FOR_DB_COPY']; ?>.
																			</div>
																		</td>
																	</tr>
																</table>
															</td>
														</tr>
													</table>
													<br>
												</td>
											</tr>
										</table>
									</td>
								</tr>
								<tr valign=top>
									<td align=left>
										<form action="install.php" method="post" name="form" id="form">
											<input type="hidden" name="file" value="SetMigrationConfig.php">
											<input type="submit" class="button" value="&#139;&#139;&nbsp;<?php echo $installationStrings['LBL_BACK']; ?>" title="<?php echo $installationStrings['LBL_BACK']; ?>" />
										</form>
									</td>
									<td align=right>
										<form action="install.php" name="migrateform" id="migrateform" method="post">
											<input type="hidden" name="auth_key" id="auth_key" value="<?php echo $_SESSION['authentication_key']; ?>" />
											<input type="hidden" name="file" value="ConfirmMigrationConfig.php" />
											<input type="hidden" name="forceDbCheck" value="true" />
											<input type="button" class="button" value="<?php echo $installationStrings['LBL_NEXT']; ?>&nbsp;&#155;&#155;" title="<?php echo $installationStrings['LBL_NEXT']; ?>" onClick="migrateform.submit();">
										</form>
									</td>
								</tr>
							</table>
						</td>
					</tr>
				</table>
				<!-- Master display stops -->
				<br>
			</td>
		</tr>
	</table>
	<table border=0 cellspacing=0 cellpadding=0 width=80% align=center>
		<tr>
			<td background="include/install/images/bottomGradient.gif"><img src="include/install/images/bottomGradient.gif"></td>
		</tr>
	</table>
	<table border=0 cellspacing=0 cellpadding=0 width=80% align=center>
		<tr>
			<td align=center><img src="include/install/images/bottomShadow.jpg"></td>
		</tr>
	</table>	
	<table border=0 cellspacing=0 cellpadding=0 width=80% align=center>
		<tr>
			<td class=small align=center> <a href="<?php echo $coreBOS_app_url; ?>" target="_blank"><?php echo $coreBOS_app_name; ?></a></td>
		</tr>
	</table>
<div id="dbMirrorCopy" class="posLayPopup" style="display: none;">
	<div class="floatRightTiny" onmouseover="this.className= 'floatRightTinyOn';" onmouseout="this.className= 'floatRightTiny';">
		<a href="javascript: void(0);" onClick="fninvsh('dbMirrorCopy');"><img src="themes/images/close.gif" border=0></a>
	</div>
	<div class="paddingPoint5em"><b><?php echo $installationStrings['LBL_COPY_OLD_DB_TO_NEW_DB'] ?></b></div>
	<table cellpadding="5" cellspacing="2" width="100%" border="0">
		<tbody>
			<tr class="dvtCellLabel">
				<td width="25%" nowrap valign='top'>
					<?php echo $installationStrings['LBL_NEW']. ' ' .$installationStrings['LBL_DATABASE_NAME']; ?> <sup><font class="redColor">*</font></sup>
				</td>
				<td>
					<input type='text' class="detailedViewTextBox" name='newDatabaseName' id='newDatabaseName' value='<?php echo $newDbForCopy ?>'>
					<br><?php echo $installationStrings['LBL_IF_DATABASE_EXISTS_WILL_RECREATE'] ?>.
				</td>
			</tr>
			<tr class="dvtCellLabel">
				<td width="25%" nowrap valign='top'>Root <?php echo $installationStrings['LBL_USER_NAME'] ?> <sup><font class="redColor">*</font></sup></td>
				<td><input type='text' class="detailedViewTextBox" name='rootUserName' id='rootUserName' value=''>
					<br><?php echo $installationStrings['LBL_SHOULD_BE_PRIVILEGED_USER'] ?>.
				</td>
			</tr>
			<tr class="dvtCellLabel">
				<td width="25%">Root <?php echo $installationStrings['LBL_PASSWORD'] ?></td>
				<td><input type='password' class="detailedViewTextBox" name='rootPassword' id='rootPassword' value=''></td>
			</tr>
			<tr class="dvtCellLabel">
				<td colspan="2" align="center"><input type='button' class='crmbuttom small create' name='copy' value='Copy Now' onclick='doDBCopy();'></td>
			</tr>
		</tbody>
	</table>
	<br>
	<div class="helpmessagebox">
		<span class='redColor fontBold'><?php echo $installationStrings['LBL_NOTE']; ?>:</span> <?php echo $installationStrings['MSG_PROCESS_TAKES_LONGER_TIME_BASED_ON_DB_SIZE']; ?>.
	</div>
</div>
<div id='responsePopupContainer' class="posLayPopup" style="display: none;" align="center">
	<div class="floatRightTiny" onmouseover="this.className= 'floatRightTinyOn';" onmouseout="this.className= 'floatRightTiny';">
		<a href="javascript: void(0);" onClick="fninvsh('responsePopupContainer');"><img src="themes/images/close.gif" border=0></a>
	</div>
	<div id='responsePopup' style="margin-top: 1.1em;" class="fontBold">&nbsp;</div>
</div>
</body>
</html>
<?php
/*+**********************************************************************************
 * The contents of this file are subject to the vtiger CRM Public License Version 1.0
 * ("License"); You may not use this file except in compliance with the License
 * The Original Code is:  vtiger CRM Open Source
 * The Initial Developer of the Original Code is vtiger.
 * Portions created by vtiger are Copyright (C) vtiger.
 * All Rights Reserved.
 ************************************************************************************/
session_start();
$current_dir = pathinfo(dirname(__FILE__));
$current_dir = $current_dir['dirname'].'/';

$cur_dir_path = false;
if (is_file('config.inc.php')) {
	require_once 'config.inc.php';
	$cur_dir_path = true;
	if (!isset($dbconfig['db_hostname']) || $dbconfig['db_status']=='_DB_STAT_') {
		$cur_dir_path = false;
	}
}

!isset($_SESSION['migration_info']['root_directory']) ? $root_directory = $current_dir : $root_directory = $_SESSION['migration_info']['root_directory'];
!isset($_SESSION['migration_info']['source_directory']) ? $source_directory = '' : $source_directory = $_SESSION['migration_info']['source_directory'];
!isset($_SESSION['migration_info']['user_name']) ? $user_name = 'admin' : $user_name = $_SESSION['migration_info']['user_name'];
!isset($_SESSION['migration_info']['user_pwd']) ? $user_pwd = '' : $user_pwd = $_SESSION['migration_info']['user_pwd'];
!isset($_SESSION['migration_info']['new_dbname']) ? $new_dbname = '' : $new_dbname = $_SESSION['migration_info']['new_dbname'];

if (isset($_SESSION['migration_info']['old_version'])) {
	$old_version = $_SESSION['migration_info']['old_version'];
} elseif (isset($_SESSION['VTIGER_DB_VERSION'])) {
	$old_version = $_SESSION['VTIGER_DB_VERSION'];
} else {
	$old_version = '';
}

include 'modules/Migration/versions.php';
$version_sorted = $versions;
uasort($version_sorted, 'version_compare');
$version_sorted = array_reverse($version_sorted, true);
$_SESSION['pre_migration'] = false;
?>

<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title><?php echo $installationStrings['APP_NAME']. ' - ' . $installationStrings['LBL_CONFIG_WIZARD']. ' - ' . $installationStrings['LBL_SYSTEM_CONFIGURATION']?></title>

	<link rel='stylesheet' type='text/css' href='themes/softed/style.css'></link>
	<script type="text/javascript" src="include/js/en_us.lang.js"></script>
	<script type="text/javascript" src="include/jquery/jquery.js"></script>
	<script type="text/javascript" src="include/js/vtlib.js"></script>
	<script type="text/javascript" src="include/js/general.js"></script>
	<link href="include/install/install.css" rel="stylesheet" type="text/css">
</head>

<body class="small cwPageBg" topmargin="0" leftmargin="0">

<script type="text/javascript">
function verify_data(form) {
	var isError = false;
	var errorMessage = '';
	// Here we decide whether to submit the form.
	if (trim(form.source_directory.value) =='') {
		isError = true;
		errorMessage += "\n <?php echo $installationStrings['LBL_PATH']; ?>";
		form.source_directory.focus();
	}
	if (trim(form.user_name.value) =='') {
		isError = true;
		errorMessage += "\n <?php echo $installationStrings['LBL_USERNAME']; ?>";
		form.user_name.focus();
	}
	if (trim(form.new_dbname.value) =='') {
		isError = true;
		errorMessage += "\n <?php echo $installationStrings['LBL_DATABASE_NAME']; ?>";
		form.new_dbname.focus();
	}
	if(form.old_version.value == ''){
		alert("<?php echo $installationStrings['LBL_SELECT_PREVIOUS_INSTALLATION_VERSION']; ?>");
		form.old_version.focus();
		return false;
	}		
	// Here we decide whether to submit the form.
	if (isError == true) {
		alert("<?php echo $installationStrings['LBL_MISSING_REQUIRED_FIELDS']; ?>:" + errorMessage);
		return false;
	}
	return true;
}
</script>

<br>
	<!-- Table for cfgwiz starts -->
<table border=0 cellspacing=0 cellpadding=0 width=85% align=center>
	<tr>
		<td class="cwHeadBg" align=left>
			<img src="include/install/images/configwizard.gif" alt="<?php echo $installationStrings['LBL_CONFIG_WIZARD']; ?>" hspace="20" title="<?php echo $installationStrings['LBL_CONFIG_WIZARD']; ?>">
		</td>
		<td class="cwHeadBg1" align=right>
			<img src="include/install/images/app_logo.png" alt="<?php echo $installationStrings['APP_NAME']; ?>" title="<?php echo $installationStrings['APP_NAME']; ?>">
		</td>
		<td class="cwHeadBg1" width=2%></td>
	</tr>
</table>
<table border=0 cellspacing=0 cellpadding=0 width=85% align=center>
	<tr>
		<td background="include/install/images/topInnerShadow.gif" align=left><img height="10" src="include/install/images/topInnerShadow.gif" ></td>
	</tr>
</table>
<table border=0 cellspacing=0 cellpadding=10 width=85% align=center>
	<tr valign="top">
		<td class="small" bgcolor="#4572BE" align=center>
			<!-- Master display -->
			<table border=0 cellspacing=0 cellpadding=10 width=97%>
				<tr>
					<td width=80% valign=top class="cwContentDisplay" align=left>
						<table border=0 cellspacing=0 cellpadding=5 width=100%>
							<tr>
								<td colspan="2" align=left class="paddingTop">
									<span class="bigHeading"><?php echo $installationStrings['LBL_SYSTEM_CONFIGURATION']; ?></span>
									<br>
									<hr noshade size=1>
								</td>
							</tr>
							<tr valign="top">
								<td align=left class="small" style="padding-left:5px" width="60%">
									<form action="install.php" method="post" name="installform" id="form">
										<!-- input type="hidden" name="file" value="PreMigrationActions.php" /-->
										<input type="hidden" name="file" value="ConfirmMigrationConfig.php" />
										<table width="100%" cellpadding="4" align=center border="0" cellspacing="0" class="level3"><tbody>
											<tr>
												<td colspan=2>
													<strong><?php echo $installationStrings['LBL_PREVIOUS_INSTALLATION_INFORMATION']; ?></strong><hr size="1" noshade=""/>
												</td>
											</tr>
											<tr>
												<td nowrap width=35%>
													<?php echo $installationStrings['LBL_PREVIOUS_INSTALLATION_PATH']; ?> <sup><font color=red>*</font></sup>
												</td>
												<td align="left">
													<?php
													if ($cur_dir_path) {
														echo $root_directory;
														?>
													<input  class="small" type="hidden" name="source_directory" id="source_directory" value="<?php echo isset($root_directory) ? $root_directory : '';?>" size="50" />
													<?php } else { ?>
													<input  class="small" type="text" name="source_directory" id="source_directory" value="<?php echo isset($source_directory) ? $source_directory : '';?>" size="50" />
													<?php } ?>
													<input class="dataInput" type="hidden" name="root_directory" id="root_directory" value="<?php echo isset($root_directory) ? $root_directory : ''; ?>" size="40" />
												</td>
											</tr>
											<tr>
												<td width = 35%>
													<?php echo $installationStrings['LBL_PREVIOUS_INSTALLATION_VERSION']; ?> <sup><font color=red>*</font></sup>
												</td>
												<td align="left">
													<select class="small" name='old_version' id='old_version'>
														<option value='' <?php echo ($old_version == '') ? 'selected' : '';?> >--SELECT--</option>
														<?php
														foreach ($version_sorted as $index => $value) {
															if ($index == $old_version) {
																echo "<option value='$index' selected>$value</option>";
															} else {
																echo "<option value='$index'>$value</option>";
															}
														}
														?>
													</select>
												</td>
											</tr>
											<tr>
												<td width = 35% >Admin <?php echo $installationStrings['LBL_USERNAME']; ?> <sup><font color=red>*</font></sup></td>
												<td align="left">
													<input class="small" type="text" name="user_name" id="user_name" value="<?php echo isset($user_name) ? $user_name : 'admin';?>" size="50" />
												</td>
											</tr>
											<tr>
												<td width = 35%>Admin <?php echo $installationStrings['LBL_PASSWORD']; ?> <sup><font color=red></font></sup></td>
												<td align="left">
													<input class="small" type="password" name="user_pwd" id="user_pwd" value="<?php echo isset($user_pwd) ? $user_pwd : '';?>" size="50" />
												</td>
											</tr>
											<tr>
												<td width = 35%><?php echo $installationStrings['LBL_MIGRATION_DATABASE_NAME']; ?> <sup><font color=red>*</font></sup></td>
												<td align="left">
													<input class="small" type="text" name="new_dbname" id="new_dbname" value="<?php echo isset($new_dbname) ? $new_dbname : '';?>" size="50" />
												</td>
											</tr>
										</table>
									</form>
								</td>
								<td class="small" style="padding-left:5px" with="40%" height="100%">
									<table width="100%" cellpadding="0" align=center border="0" cellspacing="0">
										<tr>
											<td>
												<div class="helpmessagebox paddingPoint5em">
													<span class="redColor fontBold"><?php echo $installationStrings['LBL_IMPORTANT_NOTE']; ?>:</span>
													<hr />
													<ul>
														<li><?php echo $installationStrings['MSG_TAKE_DB_BACKUP']; ?>.</li>
														<li><b><?php echo $installationStrings['QUESTION_MIGRATE_USING_NEW_DB']; ?></b>?<br>
															<ol style='padding: 0; padding-left: 15px;'>
															<li><?php echo $installationStrings['MSG_CREATE_DB_WITH_UTF8_SUPPORT']; ?>.<br>
															<font class='fontBold'><?php echo $installationStrings['LBL_EG']; ?>:</font> CREATE DATABASE <newDatabaseName> DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;</li>
															<li><?php echo $installationStrings['MSG_COPY_DATA_FROM_OLD_DB']; ?>.</li>
															</ol>
														</li>
													</ul>
												</div>
											</td>
										</tr>
									</table>
								</td>
							</tr>
							<tr>
								<td align="left">
									<input type="button" class="button" value="&#139;&#139;&nbsp;<?php echo $installationStrings['LBL_BACK']; ?>" title="<?php echo $installationStrings['LBL_BACK']; ?>" onClick="window.history.back();">
								</td>
								<td align="right">
									<input type="button" class="button" value="<?php echo $installationStrings['LBL_NEXT']; ?>&nbsp;&#155;&#155;" title="<?php echo $installationStrings['LBL_NEXT']; ?>" onClick="if(verify_data(installform) == true) document.installform.submit();">
								</td>
							</tr>
						</table>
					</td>
				</tr>
			</table>
			<!-- Master display stops -->
			<br>
		</td>
	</tr>
</table>
<table border=0 cellspacing=0 cellpadding=0 width=85% align=center>
	<tr>
		<td background="include/install/images/bottomGradient.gif"><img src="include/install/images/bottomGradient.gif"></td>
	</tr>
</table>
<table border=0 cellspacing=0 cellpadding=0 width=85% align=center>
	<tr>
		<td align=center><img src="include/install/images/bottomShadow.jpg"></td>
	</tr>
</table>
<table border=0 cellspacing=0 cellpadding=0 width=85% align=center>
	<tr>
		<td class=small align=center> <a href="<?php echo $coreBOS_app_url; ?>" target="_blank"><?php echo $coreBOS_app_name; ?></a></td>
	</tr>
</table>

<!-- To prefetch the images for blocking the screen -->
<img style="display: none;" src="include/install/images/loading.gif">
<img style="display: none;" src="themes/softed/images/layerPopupBg.gif">
<!-- END -->
</body>
</html>
<?php
/*+**********************************************************************************
 * The contents of this file are subject to the vtiger CRM Public License Version 1.0
 * ("License"); You may not use this file except in compliance with the License
 * The Original Code is:  vtiger CRM Open Source
 * The Initial Developer of the Original Code is vtiger.
 * Portions created by vtiger are Copyright (C) vtiger.
 * All Rights Reserved.
 ************************************************************************************/

include 'include/adodb/adodb.inc.php';

if (version_compare(phpversion(), '5.5') < 0) {
	$serverPhpVersion = phpversion();
	require_once 'phpversionfail.php';
	die();
}

require_once 'include/install/language/en_us.lang.php';
require_once 'include/install/resources/utils.php';
require_once 'vtigerversion.php';
global $installationStrings, $vtiger_current_version, $coreBOS_app_version, $current_user, $adb;
include_once 'vtlib/Vtiger/Module.php';
error_reporting(E_ERROR);
ini_set('display_errors', 'on');
$current_user = Users::getActiveAdminUser();

@include_once 'install/config.db.php';
$adb->query("SET SESSION sql_mode = ''");
$adb->query('CREATE TABLE IF NOT EXISTS vtiger_crmobject (
	crmid int(19),
	cbuuid char(40),
	deleted tinyint(1),
	setype varchar(100),
	smownerid int(19),
	modifiedtime datetime,
	PRIMARY KEY (crmid),
	INDEX (cbuuid),
	INDEX (deleted),
	INDEX (setype)
	) ENGINE=InnoDB DEFAULT CHARSET=utf8');

// mandatory coreBOS DB changes
$result = $adb->pquery('show columns from com_vtiger_workflowtasks like ?', array('executionorder'));
if (!($adb->num_rows($result))) {
	$adb->query('ALTER TABLE com_vtiger_workflowtasks ADD executionorder INT(10)', array());
	$adb->query('ALTER TABLE `com_vtiger_workflowtasks` ADD INDEX(`executionorder`)');
}
$result = $adb->pquery("show columns from com_vtiger_workflows like ?", array('schminuteinterval'));
if (!($adb->num_rows($result))) {
	$adb->query("ALTER TABLE com_vtiger_workflows ADD schminuteinterval VARCHAR(200)", array());
}
$adb->query("CREATE TABLE IF NOT EXISTS com_vtiger_workflow_tasktypes (
				id int(11) NOT NULL,
				tasktypename varchar(255) NOT NULL,
				label varchar(255),
				classname varchar(255),
				classpath varchar(255),
				templatepath varchar(255),
				modules text(500),
				sourcemodule varchar(255)
				) ENGINE=InnoDB DEFAULT CHARSET=utf8", array());
$result = $adb->pquery("show columns from com_vtiger_workflows like ?", array('schtypeid'));
if (!($adb->num_rows($result))) {
	$adb->query("ALTER TABLE com_vtiger_workflows ADD schtypeid INT(10)");
}
$result = $adb->pquery("show columns from com_vtiger_workflows like ?", array('schtime'));
if (!($adb->num_rows($result))) {
	$adb->query("ALTER TABLE com_vtiger_workflows ADD schtime TIME");
} else {
	$adb->query('ALTER TABLE com_vtiger_workflows CHANGE schtime schtime TIME NULL DEFAULT NULL');
}
$result = $adb->pquery("show columns from com_vtiger_workflows like ?", array('schdayofmonth'));
if (!($adb->num_rows($result))) {
	$adb->query("ALTER TABLE com_vtiger_workflows ADD schdayofmonth VARCHAR(200)");
}
$result = $adb->pquery("show columns from com_vtiger_workflows like ?", array('schdayofweek'));
if (!($adb->num_rows($result))) {
	$adb->query("ALTER TABLE com_vtiger_workflows ADD schdayofweek VARCHAR(200)");
}
$result = $adb->pquery("show columns from com_vtiger_workflows like ?", array('schannualdates'));
if (!($adb->num_rows($result))) {
	$adb->query("ALTER TABLE com_vtiger_workflows ADD schannualdates VARCHAR(200)");
}
$result = $adb->pquery("show columns from com_vtiger_workflows like ?", array('nexttrigger_time'));
if (!($adb->num_rows($result))) {
	$adb->query("ALTER TABLE com_vtiger_workflows ADD nexttrigger_time DATETIME");
}
$result = $adb->pquery("show columns from com_vtiger_workflows like ?", array('purpose'));
if (!($adb->num_rows($result))) {
	$adb->query("ALTER TABLE `com_vtiger_workflows` ADD `purpose` TEXT NULL;");
}
$result = $adb->pquery('show columns from com_vtiger_workflows like ?', array('relatemodule'));
if (!($adb->num_rows($result))) {
	$adb->query('ALTER TABLE `com_vtiger_workflows` ADD `relatemodule` varchar(100) default NULL;');
}
$result = $adb->pquery('show columns from com_vtiger_workflows like ?', array('options'));
if (!($adb->num_rows($result))) {
	$adb->query('ALTER TABLE com_vtiger_workflows ADD options VARCHAR(100)');
}
$result = $adb->pquery('show columns from com_vtiger_workflows like ?', array('cbquestion'));
if (!($adb->num_rows($result))) {
	$adb->query('ALTER TABLE com_vtiger_workflows ADD cbquestion INT(11)');
}
$result = $adb->pquery('show columns from com_vtiger_workflows like ?', array('recordset'));
if (!($adb->num_rows($result))) {
	$adb->query('ALTER TABLE com_vtiger_workflows ADD recordset INT(11)');
}
$result = $adb->pquery('show columns from com_vtiger_workflows like ?', array('onerecord'));
if (!($adb->num_rows($result))) {
	$adb->query('ALTER TABLE com_vtiger_workflows ADD onerecord INT(11)');
}
$taskTypes = array();
$defaultModules = array('include' => array(), 'exclude'=>array());
$createToDoModules = array('include' => array("Leads","Accounts","Potentials","Contacts","HelpDesk","Campaigns","Quotes","PurchaseOrder","SalesOrder","Invoice"), 'exclude'=>array("Calendar", "FAQ", "Events"));
$createEventModules = array('include' => array("Leads","Accounts","Potentials","Contacts","HelpDesk","Campaigns"), 'exclude'=>array("Calendar", "FAQ", "Events"));

$taskTypes[] = array("name"=>"VTEmailTask", "label"=>"Send Mail", "classname"=>"VTEmailTask", "classpath"=>"modules/com_vtiger_workflow/tasks/VTEmailTask.inc", "templatepath"=>"com_vtiger_workflow/taskforms/VTEmailTask.tpl", "modules"=>$defaultModules, "sourcemodule"=>'');
$taskTypes[] = array("name"=>"VTEntityMethodTask", "label"=>"Invoke Custom Function", "classname"=>"VTEntityMethodTask", "classpath"=>"modules/com_vtiger_workflow/tasks/VTEntityMethodTask.inc", "templatepath"=>"com_vtiger_workflow/taskforms/VTEntityMethodTask.tpl", "modules"=>$defaultModules, "sourcemodule"=>'');
$taskTypes[] = array("name"=>"VTCreateTodoTask", "label"=>"Create Todo", "classname"=>"VTCreateTodoTask", "classpath"=>"modules/com_vtiger_workflow/tasks/VTCreateTodoTask.inc", "templatepath"=>"com_vtiger_workflow/taskforms/VTCreateTodoTask.tpl", "modules"=>$createToDoModules, "sourcemodule"=>'');
$taskTypes[] = array("name"=>"VTUpdateFieldsTask", "label"=>"Update Fields", "classname"=>"VTUpdateFieldsTask", "classpath"=>"modules/com_vtiger_workflow/tasks/VTUpdateFieldsTask.inc", "templatepath"=>"com_vtiger_workflow/taskforms/VTUpdateFieldsTask.tpl", "modules"=>$defaultModules, "sourcemodule"=>'');
$taskTypes[] = array("name"=>"VTCreateEntityTask", "label"=>"Create Entity", "classname"=>"VTCreateEntityTask", "classpath"=>"modules/com_vtiger_workflow/tasks/VTCreateEntityTask.inc", "templatepath"=>"com_vtiger_workflow/taskforms/VTCreateEntityTask.tpl", "modules"=>$defaultModules, "sourcemodule"=>'');
$taskTypes[] = array("name"=>"VTSMSTask", "label"=>"SMS Task", "classname"=>"VTSMSTask", "classpath"=>"modules/com_vtiger_workflow/tasks/VTSMSTask.inc", "templatepath"=>"com_vtiger_workflow/taskforms/VTSMSTask.tpl", "modules"=>$defaultModules, "sourcemodule"=>'SMSNotifier');

foreach ($taskTypes as $taskType) {
	VTTaskType::registerTaskType($taskType);
}

$adb->query('ALTER TABLE `vtiger_currency_info` ADD `currency_position` CHAR(4) NOT NULL;');
$adb->query("UPDATE `vtiger_currency_info` SET `currency_position` = '$1.0';");
$adb->query("UPDATE `vtiger_currency_info` SET `currency_position` = '1.0$' where currency_name='Euro';");
$adb->query("ALTER TABLE vtiger_profile2field ADD summary enum('T', 'H','B', 'N') DEFAULT 'B' NOT NULL");

$adb->query('CREATE TABLE `cb_settings` (
	`setting_key` varchar(200) NOT NULL,
	`setting_value` varchar(1000) NOT NULL,
	PRIMARY KEY (`setting_key`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8');

$adb->query('ALTER TABLE `vtiger_email_access` CHANGE `accesstime` `accesstime` TIME NULL DEFAULT NULL');
$adb->query('ALTER TABLE `vtiger_users` CHANGE `date_entered` `date_entered` DATETIME NOT NULL');
$adb->query('ALTER TABLE `vtiger_users` CHANGE `date_modified` `date_modified` TIMESTAMP on update CURRENT_TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP;');
$adb->query('ALTER TABLE `vtiger_import_maps` CHANGE `date_entered` `date_entered` DATETIME NOT NULL');
$adb->query('ALTER TABLE `vtiger_import_maps` CHANGE `date_modified` `date_modified` TIMESTAMP on update CURRENT_TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP;');
$adb->query('ALTER TABLE `vtiger_loginhistory` CHANGE `login_time` `login_time` TIMESTAMP NULL DEFAULT NULL;');
$adb->query('ALTER TABLE `vtiger_loginhistory` CHANGE `logout_time` `logout_time` TIMESTAMP NULL DEFAULT NULL');
$adb->query("UPDATE `vtiger_users` set date_modified=date_entered");
$adb->query("UPDATE `vtiger_import_maps` set date_modified=date_entered");
$adb->query("UPDATE `vtiger_loginhistory` set login_time=null where login_time='0000-00-00 00:00:00'");
$adb->query("UPDATE `vtiger_loginhistory` set logout_time=null where logout_time='0000-00-00 00:00:00'");
$adb->query("UPDATE `vtiger_crmentity` set modifiedtime=createdtime where modifiedtime='0000-00-00 00:00:00'");
//

$the_file = 'CheckSystem.php';
Common_Install_Wizard_Utils::checkFileAccessForInclusion("install/".$the_file);
$_REQUEST['filename'] = 'SetMigrationConfig.php';
$_REQUEST['file'] = 'CheckSystem.php';
$_REQUEST['migrate'] = 'true';

include 'install/'.$the_file;
?>

Fixed code: