2 if(!defined('sugarEntry'))define('sugarEntry', true);
3 /*********************************************************************************
4 * SugarCRM Community Edition is a customer relationship management program developed by
5 * SugarCRM, Inc. Copyright (C) 2004-2012 SugarCRM Inc.
7 * This program is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU Affero General Public License version 3 as published by the
9 * Free Software Foundation with the addition of the following permission added
10 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
11 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
12 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
19 * You should have received a copy of the GNU Affero General Public License along with
20 * this program; if not, see http://www.gnu.org/licenses or write to the Free
21 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
25 * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
27 * The interactive user interfaces in modified source and object code versions
28 * of this program must display Appropriate Legal Notices, as required under
29 * Section 5 of the GNU Affero General Public License version 3.
31 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
32 * these Appropriate Legal Notices must retain the display of the "Powered by
33 * SugarCRM" logo. If the display of the logo is not reasonably feasible for
34 * technical reasons, the Appropriate Legal Notices must display the words
35 * "Powered by SugarCRM".
36 ********************************************************************************/
39 if (version_compare(phpversion(),'5.2.0') < 0) {
40 $msg = 'Minimum PHP version required is 5.2.0. You are using PHP version '. phpversion();
43 $session_id = session_id();
44 if(empty($session_id)){
47 $GLOBALS['installing'] = true;
48 define('SUGARCRM_IS_INSTALLING', $GLOBALS['installing']);
49 $GLOBALS['sql_queries'] = 0;
50 require_once('include/SugarLogger/LoggerManager.php');
51 require_once('sugar_version.php');
52 require_once('include/utils.php');
53 require_once('install/install_utils.php');
54 require_once('install/install_defaults.php');
55 require_once('include/TimeDate.php');
56 require_once('include/Localization/Localization.php');
57 require_once('include/SugarTheme/SugarTheme.php');
58 require_once('include/utils/LogicHook.php');
59 require_once('data/SugarBean.php');
60 require_once('include/entryPoint.php');
61 //check to see if the script files need to be rebuilt, add needed variables to request array
62 $_REQUEST['root_directory'] = getcwd();
63 $_REQUEST['js_rebuild_concat'] = 'rebuild';
64 if(isset($_REQUEST['goto']) && $_REQUEST['goto'] != 'SilentInstall') {
65 require_once('jssource/minify.php');
68 $timedate = TimeDate::getInstance();
69 // cn: set php.ini settings at entry points
71 $locale = new Localization();
73 if(get_magic_quotes_gpc() == 1) {
74 $_REQUEST = array_map("stripslashes_checkstrings", $_REQUEST);
75 $_POST = array_map("stripslashes_checkstrings", $_POST);
76 $_GET = array_map("stripslashes_checkstrings", $_GET);
80 $GLOBALS['log'] = LoggerManager::getLogger('SugarCRM');
81 $setup_sugar_version = $sugar_version;
82 $install_script = true;
84 ///////////////////////////////////////////////////////////////////////////////
85 //// INSTALL RESOURCE SETUP
86 $css = 'install/install.css';
87 $icon = 'include/images/sugar_icon.ico';
88 $sugar_md = 'include/images/sugar_md_open.png';
89 $loginImage = 'include/images/sugarcrm_login.png';
90 $common = 'install/installCommon.js';
92 ///////////////////////////////////////////////////////////////////////////////
93 //// INSTALLER LANGUAGE
94 function getSupportedInstallLanguages(){
95 $supportedLanguages = array(
96 'en_us' => 'English (US)',
98 if(file_exists('install/lang.config.php')){
99 include('install/lang.config.php');
100 if(!empty($config['languages'])){
102 foreach($config['languages'] as $k=>$v){
103 if(file_exists('install/language/' . $k . '.lang.php')){
104 $supportedLanguages[$k] = $v;
109 return $supportedLanguages;
111 $supportedLanguages = getSupportedInstallLanguages();
113 // after install language is selected, use that pack
114 $default_lang = 'en_us';
115 if(!isset($_POST['language']) && (!isset($_SESSION['language']) && empty($_SESSION['language']))) {
116 if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) && !empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
117 $lang = parseAcceptLanguage();
118 if(isset($supportedLanguages[$lang])) {
119 $_POST['language'] = $lang;
121 $_POST['language'] = $default_lang;
126 if(isset($_POST['language'])) {
127 $_SESSION['language'] = str_replace('-','_',$_POST['language']);
130 $current_language = isset($_SESSION['language']) ? $_SESSION['language'] : $default_lang;
132 if(file_exists("install/language/{$current_language}.lang.php")) {
133 require_once("install/language/{$current_language}.lang.php");
135 require_once("install/language/{$default_lang}.lang.php");
138 if($current_language != 'en_us') {
139 $my_mod_strings = $mod_strings;
140 include('install/language/en_us.lang.php');
141 $mod_strings = sugarArrayMerge($mod_strings, $my_mod_strings);
143 //// END INSTALLER LANGUAGE
144 ///////////////////////////////////////////////////////////////////////////////
146 //get the url for the helper link
147 $help_url = get_help_button_url();
149 //if this license print, then redirect and exit,
150 if(isset($_REQUEST['page']) && $_REQUEST['page'] == 'licensePrint')
152 include('install/licensePrint.php');
156 if(isset($_REQUEST['sugar_body_only']) && $_REQUEST['sugar_body_only'] == "1") {
157 //if this is a system check, then just run the check and return,
158 //this is an ajax call and there is no need for further processing
159 if(isset($_REQUEST['checkInstallSystem']) && ($_REQUEST['checkInstallSystem'])){
160 require_once('install/installSystemCheck.php');
161 echo runCheck($install_script, $mod_strings);
165 //if this is a DB Settings check, then just run the check and return,
166 //this is an ajax call and there is no need for further processing
167 if(isset($_REQUEST['checkDBSettings']) && ($_REQUEST['checkDBSettings'])){
168 require_once('install/checkDBSettings.php');
169 echo checkDBSettings();
174 //maintaining the install_type if earlier set to custom
175 if(isset($_REQUEST['install_type']) && $_REQUEST['install_type'] == 'custom'){
176 $_SESSION['install_type'] = $_REQUEST['install_type'];
179 //set the default settings into session
180 foreach($installer_defaults as $key =>$val){
181 if(!isset($_SESSION[$key])){
182 $_SESSION[$key] = $val;
187 clean_special_arguments();
188 print_debug_comment();
189 $next_clicked = false;
192 // use a simple array to map out the steps of the installer page flow
193 $workflow = array( 'welcome.php',
198 $workflow[] = 'systemOptions.php';
199 $workflow[] = 'dbConfig_a.php';
200 //$workflow[] = 'dbConfig_b.php';
202 //define web root, which will be used as default for site_url
203 if($_SERVER['SERVER_PORT']=='80'){
204 $web_root = $_SERVER['SERVER_NAME'].$_SERVER['PHP_SELF'];
206 $web_root = $_SERVER['SERVER_NAME'].':'.$_SERVER['SERVER_PORT'].$_SERVER['PHP_SELF'];
208 $web_root = str_replace("/install.php", "", $web_root);
209 $web_root = "http://$web_root";
211 if (!isset($_SESSION['oc_install']) || $_SESSION['oc_install'] == false) {
212 $workflow[] = 'siteConfig_a.php';
213 if (isset($_SESSION['install_type']) && !empty($_SESSION['install_type']) &&
214 $_SESSION['install_type'] == 'custom') {
215 $workflow[] = 'siteConfig_b.php';
218 if (is_readable('config.php')) {
219 require_once ('config.php');
223 if(empty($sugar_config['cache_dir']) && !empty($_SESSION['cache_dir'])) {
224 $sugar_config['cache_dir'] = $_SESSION['cache_dir'];
227 // set the form's php var to the loaded config's var else default to sane settings
228 if(!isset($_SESSION['setup_site_url']) || empty($_SESSION['setup_site_url'])) {
229 if(isset($sugar_config['site_url']) && !empty($sugar_config['site_url'])) {
230 $_SESSION['setup_site_url']= $sugar_config['site_url'];
232 $_SESSION['setup_site_url']= $web_root;
236 if (!isset($_SESSION['setup_system_name']) || empty($_SESSION['setup_system_name'])) {
237 $_SESSION['setup_system_name'] = 'SugarCRM';
239 if (!isset($_SESSION['setup_site_session_path']) || empty($_SESSION['setup_site_session_path'])) {
240 $_SESSION['setup_site_session_path'] = (isset($sugar_config['session_dir'])) ? $sugar_config['session_dir'] : '';
242 if (!isset($_SESSION['setup_site_log_dir']) || empty($_SESSION['setup_site_log_dir'])) {
243 $_SESSION['setup_site_log_dir'] = (isset($sugar_config['log_dir'])) ? $sugar_config['log_dir'] : '.';
245 if (!isset($_SESSION['setup_site_guid']) || empty($_SESSION['setup_site_guid'])) {
246 $_SESSION['setup_site_guid'] = (isset($sugar_config['unique_key'])) ? $sugar_config['unique_key'] : '';
248 if (!isset($_SESSION['cache_dir']) || empty($_SESSION['cache_dir'])) {
249 $_SESSION['cache_dir'] = isset($sugar_config['cache_dir']) ? $sugar_config['cache_dir'] : 'cache/';
252 $workflow[] = 'confirmSettings.php';
253 $workflow[] = 'performSetup.php';
255 if(!isset($_SESSION['oc_install']) || $_SESSION['oc_install'] == false){
256 if(isset($_SESSION['install_type']) && !empty($_SESSION['install_type']) && $_SESSION['install_type']=='custom'){
257 //$workflow[] = 'download_patches.php';
258 $workflow[] = 'download_modules.php';
262 $workflow[] = 'register.php';
265 // increment/decrement the workflow pointer
266 if(!empty($_REQUEST['goto'])) {
267 switch($_REQUEST['goto']) {
268 case $mod_strings['LBL_CHECKSYS_RECHECK']:
269 $next_step = $_REQUEST['current_step'];
271 case $mod_strings['LBL_BACK']:
272 $next_step = $_REQUEST['current_step'] - 1;
274 case $mod_strings['LBL_NEXT']:
275 case $mod_strings['LBL_START']:
276 $next_step = $_REQUEST['current_step'] + 1;
277 $next_clicked = true;
279 case 'SilentInstall':
287 // Add check here to see if a silent install config file exists; if so then launch silent installer
288 elseif ( is_file('config_si.php') && empty($sugar_config['installer_locked'])) {
290 $langHeader = get_language_header();
293 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
296 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
297 <meta http-equiv="Content-Style-Type" content="text/css">
298 <meta http-equiv="Refresh" content="1; url=install.php?goto=SilentInstall&cli=true">
299 <title>{$mod_strings['LBL_WIZARD_TITLE']} {$mod_strings['LBL_TITLE_WELCOME']} {$setup_sugar_version} {$mod_strings['LBL_WELCOME_SETUP_WIZARD']}</title>
300 <link REL="SHORTCUT ICON" HREF="{$icon}">
301 <link rel="stylesheet" href="{$css}" type="text/css">
304 <table cellspacing="0" cellpadding="0" border="0" align="center" class="shell">
306 <td colspan="2" id="help"><a href="{$help_url}" target='_blank'>{$mod_strings['LBL_HELP']} </a></td></tr>
310 <img src="{$sugar_md}" alt="SugarCRM" border="0">
312 {$mod_strings['LBL_TITLE_WELCOME']} {$setup_sugar_version} {$mod_strings['LBL_WELCOME_SETUP_WIZARD']}</th>
314 <th width="200" height="30" style="text-align: right;"><a href="http://www.sugarcrm.com" target="_blank"><IMG src="{$loginImage}" width="145" height="30" alt="SugarCRM" border="0"></a>
318 <td colspan="2" id="ready_image"><IMG src="include/images/install_themes.jpg" width="698" height="247" alt="Sugar Themes" border="0"></td>
322 <td colspan="2" id="ready">{$mod_strings['LBL_LAUNCHING_SILENT_INSTALL']} </td>
333 $exclude_files = array('register.php','download_modules.php');
335 if(isset($next_step) && isset($workflow[$next_step]) && !in_array($workflow[$next_step],$exclude_files) && isset($sugar_config['installer_locked']) && $sugar_config['installer_locked'] == true) {
336 $the_file = 'installDisabled.php';
337 $disabled_title = $mod_strings['LBL_DISABLED_DESCRIPTION'];
338 $disabled_title_2 = $mod_strings['LBL_DISABLED_TITLE_2'];
339 $disabled_text =<<<EOQ
340 <p>{$mod_strings['LBL_DISABLED_DESCRIPTION']}</p>
342 'installer_locked' => false,
344 <p>{$mod_strings['LBL_DISABLED_DESCRIPTION_2']}</p>
346 <p>{$mod_strings['LBL_DISABLED_HELP_1']} <a href="{$mod_strings['LBL_DISABLED_HELP_LNK']}" target="_blank">{$mod_strings['LBL_DISABLED_HELP_2']}</a>.</p>
350 $validation_errors = array();
351 // process the data posted
353 // store the submitted data because the 'Next' button was clicked
354 switch($workflow[trim($_REQUEST['current_step'])]) {
356 $_SESSION['language'] = $_REQUEST['language'];
357 $_SESSION['setup_site_admin_user_name'] = 'admin';
360 $_SESSION['setup_license_accept'] = get_boolean_from_request('setup_license_accept');
361 $_SESSION['license_submitted'] = true;
364 // eventually default all vars here, with overrides from config.php
365 if(is_readable('config.php')) {
366 global $sugar_config;
367 include_once('config.php');
370 $default_db_type = 'mysql';
372 if(!isset($_SESSION['setup_db_type'])) {
373 $_SESSION['setup_db_type'] = empty($sugar_config['dbconfig']['db_type']) ? $default_db_type : $sugar_config['dbconfig']['db_type'];
377 case 'installType.php':
378 $_SESSION['install_type'] = $_REQUEST['install_type'];
379 if(isset($_REQUEST['setup_license_key']) && !empty($_REQUEST['setup_license_key'])){
380 $_SESSION['setup_license_key'] = $_REQUEST['setup_license_key'];
382 $_SESSION['licenseKey_submitted'] = true;
388 case 'systemOptions.php':
389 $_SESSION['setup_db_type'] = $_REQUEST['setup_db_type'];
390 $validation_errors = validate_systemOptions();
391 if(count($validation_errors) > 0) {
396 case 'dbConfig_a.php':
397 //validation is now done through ajax call to checkDBSettings.php
398 if(isset($_REQUEST['setup_db_drop_tables'])){
399 $_SESSION['setup_db_drop_tables'] = $_REQUEST['setup_db_drop_tables'];
400 if($_SESSION['setup_db_drop_tables']=== true || $_SESSION['setup_db_drop_tables'] == 'true'){
401 $_SESSION['setup_db_create_database'] = false;
406 case 'siteConfig_a.php':
407 if(isset($_REQUEST['setup_site_url'])){$_SESSION['setup_site_url'] = $_REQUEST['setup_site_url'];}
408 if(isset($_REQUEST['setup_system_name'])){$_SESSION['setup_system_name'] = $_REQUEST['setup_system_name'];}
409 if(isset($_REQUEST['setup_db_collation'])) {
410 $_SESSION['setup_db_options']['collation'] = $_REQUEST['setup_db_collation'];
412 $_SESSION['setup_site_admin_user_name'] = $_REQUEST['setup_site_admin_user_name'];
413 $_SESSION['setup_site_admin_password'] = $_REQUEST['setup_site_admin_password'];
414 $_SESSION['setup_site_admin_password_retype'] = $_REQUEST['setup_site_admin_password_retype'];
415 $_SESSION['siteConfig_submitted'] = true;
417 $validation_errors = array();
418 $validation_errors = validate_siteConfig('a');
419 if(count($validation_errors) > 0) {
423 case 'siteConfig_b.php':
424 $_SESSION['setup_site_sugarbeet_automatic_checks'] = get_boolean_from_request('setup_site_sugarbeet_automatic_checks');
426 $_SESSION['setup_site_custom_session_path'] = get_boolean_from_request('setup_site_custom_session_path');
427 if($_SESSION['setup_site_custom_session_path']){
428 $_SESSION['setup_site_session_path'] = $_REQUEST['setup_site_session_path'];
430 $_SESSION['setup_site_session_path'] = '';
433 $_SESSION['setup_site_custom_log_dir'] = get_boolean_from_request('setup_site_custom_log_dir');
434 if($_SESSION['setup_site_custom_log_dir']){
435 $_SESSION['setup_site_log_dir'] = $_REQUEST['setup_site_log_dir'];
437 $_SESSION['setup_site_log_dir'] = '.';
440 $_SESSION['setup_site_specify_guid'] = get_boolean_from_request('setup_site_specify_guid');
441 if($_SESSION['setup_site_specify_guid']){
442 $_SESSION['setup_site_guid'] = $_REQUEST['setup_site_guid'];
444 $_SESSION['setup_site_guid'] = '';
446 $_SESSION['siteConfig_submitted'] = true;
447 if(isset($_REQUEST['setup_site_sugarbeet_anonymous_stats'])){
448 $_SESSION['setup_site_sugarbeet_anonymous_stats'] = get_boolean_from_request('setup_site_sugarbeet_anonymous_stats');
450 $_SESSION['setup_site_sugarbeet_anonymous_stats'] = 0;
453 $validation_errors = array();
454 $validation_errors = validate_siteConfig('b');
455 if(count($validation_errors) > 0) {
462 if($next_step == 9999) {
463 $the_file = 'SilentInstall';
464 }else if($next_step == 9191) {
465 $_SESSION['oc_server_url'] = $_REQUEST['oc_server_url'];
466 $_SESSION['oc_username'] = $_REQUEST['oc_username'];
467 $_SESSION['oc_password'] = $_REQUEST['oc_password'];
468 $the_file = 'oc_convert.php';
471 $the_file = $workflow[$next_step];
479 // Check to see if session variables are working properly
481 $_SESSION['test_session'] = 'sessions are available';
482 @session_write_close();
483 unset($_SESSION['test_session']);
486 if(!isset($_SESSION['test_session']))
488 $the_file = 'installDisabled.php';
489 // PHP.ini location -
490 $phpIniLocation = get_cfg_var("cfg_file_path");
491 $disabled_title = $mod_strings['LBL_SESSION_ERR_TITLE'];
492 $disabled_title_2 = $mod_strings['LBL_SESSION_ERR_TITLE'];
493 $disabled_text = $mod_strings['LBL_SESSION_ERR_DESCRIPTION']."<pre>{$phpIniLocation}</pre>";
496 // check to see if installer has been disabled
497 if(is_readable('config.php') && (filesize('config.php') > 0)) {
498 include_once('config.php');
500 if(!isset($sugar_config['installer_locked']) || $sugar_config['installer_locked'] == true) {
501 $the_file = 'installDisabled.php';
502 $disabled_title = $mod_strings['LBL_DISABLED_DESCRIPTION'];
503 $disabled_title_2 = $mod_strings['LBL_DISABLED_TITLE_2'];
504 $disabled_text =<<<EOQ
505 <p>{$mod_strings['LBL_DISABLED_DESCRIPTION']}</p>
507 'installer_locked' => false,
509 <p>{$mod_strings['LBL_DISABLED_DESCRIPTION_2']}</p>
511 <p>{$mod_strings['LBL_DISABLED_HELP_1']} <a href="{$mod_strings['LBL_DISABLED_HELP_LNK']}" target="_blank">{$mod_strings['LBL_DISABLED_HELP_2']}</a>.</p>
513 //if this is an offline client installation but the conversion did not succeed,
514 //then try to convert again
515 if(isset($sugar_config['disc_client']) && $sugar_config['disc_client'] == true && isset($sugar_config['oc_converted']) && $sugar_config['oc_converted'] == false) {
516 header('Location: index.php?entryPoint=oc_convert&first_time=true');
525 case 'SilentInstall':
527 pullSilentInstallVarsIntoSession();
528 $validation_errors = validate_dbConfig('a');
529 if(count($validation_errors) > 0) {
530 $the_file = 'dbConfig_a.php';
533 $validation_errors = validate_siteConfig('a');
534 if(count($validation_errors) > 0) {
535 $the_file = 'siteConfig_a.php';
538 $validation_errors = validate_siteConfig('b');
539 if(count($validation_errors) > 0) {
540 $the_file = 'siteConfig_b.php';
545 $the_file = 'performSetup.php';
547 require_once('jssource/minify.php');
548 //since this is a SilentInstall we still need to make sure that
549 //the appropriate files are writable
551 make_writable('./config.php');
554 make_writable('./custom');
557 recursive_make_writable('./modules');
560 create_writable_dir(sugar_cached('custom_fields'));
561 create_writable_dir(sugar_cached('dyn_lay'));
562 create_writable_dir(sugar_cached('images'));
563 create_writable_dir(sugar_cached('layout'));
564 create_writable_dir(sugar_cached('pdf'));
565 create_writable_dir(sugar_cached('upload/import'));
566 create_writable_dir(sugar_cached('xml'));
567 create_writable_dir(sugar_cached('include/javascript'));
569 // check whether we're getting this request from a command line tool
570 // we want to output brief messages if we're outputting to a command line tool
572 if(isset($_REQUEST['cli']) && ($_REQUEST['cli'] == 'true')) {
573 $_SESSION['cli'] = true;
574 // if we have errors, just shoot them back now
575 if(count($validation_errors) > 0) {
576 foreach($validation_errors as $error) {
577 print($mod_strings['ERR_ERROR_GENERAL']."\n");
578 print(" " . $error . "\n");
589 $the_file = clean_string($the_file, 'FILE');
591 installerHook('pre_installFileRequire', array('the_file' => $the_file));
593 // change to require to get a good file load error message if the file is not available.
594 require('install/' . $the_file);
596 installerHook('post_installFileRequire', array('the_file' => $the_file));