. /** * This script creates config.php file during installation. * * @package moodlecore * @subpackage install * @copyright 2009 Petr Skoda (http://skodak.org) * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ if (isset($_REQUEST['lang'])) { $lang = preg_replace('/[^A-Za-z0-9_-]/i', '', $_REQUEST['lang']); } else { $lang = 'en_utf8'; } if (isset($_REQUEST['admin'])) { $admin = preg_replace('/[^A-Za-z0-9_-]/i', '', $_REQUEST['admin']); } else { $admin = 'admin'; } // If config.php exists we just created config.php and need to redirect to continue installation $configfile = './config.php'; if (file_exists($configfile)) { header("Location: $admin/index.php?lang=$lang"); die; } // make sure PHP errors are displayed - helps with diagnosing of problems @error_reporting(E_ALL); @ini_set('display_errors', '1'); // we need a lot of memory @ini_set('memory_limit', '40M'); // Check that PHP is of a sufficient version if (version_compare(phpversion(), "5.2.0") < 0) { $phpversion = phpversion(); // do NOT localise - lang strings would not work here and we CAN not move it after installib echo "Sorry, Moodle 2.0 requires PHP 5.2.8 or later (currently using version $phpversion). "; echo "Please upgrade your server software or install latest Moodle 1.9.x instead."; die; } require dirname(__FILE__).'/lib/installlib.php'; // TODO: add lang detection here if empty $_REQUEST['lang'] // distro specific customisation $distro = null; if (file_exists('install/distrolib.php')) { require_once('install/distrolib.php'); if (function_exists('distro_get_config')) { $distro = distro_get_config(); } } $config = new stdClass(); $config->lang = $lang; if (!empty($_POST)) { if (install_ini_get_bool('magic_quotes_gpc')) { $_POST = array_map('stripslashes', $_POST); } $config->stage = (int)$_POST['stage']; if (isset($_POST['previous'])) { $config->stage--; if (INSTALL_DATABASETYPE and !empty($distro->dbtype)) { $config->stage--; } if ($config->stage == INSTALL_ENVIRONMENT or $config->stage == INSTALL_DOWNLOADLANG) { $config->stage--; } } else if (isset($_POST['next'])) { $config->stage++; } $config->dbtype = trim($_POST['dbtype']); $config->dbhost = trim($_POST['dbhost']); $config->dbuser = trim($_POST['dbuser']); $config->dbpass = trim($_POST['dbpass']); $config->dbname = trim($_POST['dbname']); $config->prefix = trim($_POST['prefix']); $config->dbsocket = (int)(!empty($_POST['dbsocket'])); $config->dirroot = trim($_POST['dirroot']); $config->admin = empty($_POST['admin']) ? 'admin' : trim($_POST['admin']); $config->dataroot = trim($_POST['dataroot']); } else { $config->stage = INSTALL_WELCOME; $config->dbtype = empty($distro->dbtype) ? '' : $distro->dbtype; // let distro skip dbtype selection $config->dbhost = empty($distro->dbhost) ? 'localhost' : $distro->dbhost; // let distros set dbhost $config->dbuser = empty($distro->dbuser) ? '' : $distro->dbuser; // let distros set dbuser $config->dbpass = ''; $config->dbname = 'moodle'; $config->prefix = 'mdl_'; $config->dbsocket = 0; $config->dirroot = str_replace('\\', '/', dirname(__FILE__)); // Fix for win32 $config->admin = 'admin'; $config->dataroot = empty($distro->dataroot) ? null : $distro->dataroot; // initialised later after including libs or by distro } // Fake some settings so that we can use selected functions from moodlelib.php and weblib.php $CFG = new stdClass(); $CFG->lang = $config->lang; $CFG->dirroot = str_replace('\\', '/', dirname(__FILE__)); // Fix for win32 $CFG->libdir = "$CFG->dirroot/lib"; $CFG->wwwroot = install_guess_wwwroot(); // can not be changed - ppl must use the real address when installing $CFG->httpswwwroot = $CFG->wwwroot; $CFG->httpsthemewww = $CFG->wwwroot; $CFG->dataroot = $config->dataroot; $CFG->admin = $config->admin; $CFG->docroot = 'http://docs.moodle.org'; $CFG->directorypermissions = 00777; $CFG->running_installer = true; // Require all needed libs require_once($CFG->libdir.'/setuplib.php'); require_once($CFG->libdir.'/textlib.class.php'); require_once($CFG->libdir.'/weblib.php'); require_once($CFG->libdir.'/dmllib.php'); require_once($CFG->libdir.'/moodlelib.php'); require_once($CFG->libdir.'/deprecatedlib.php'); require_once($CFG->libdir.'/adminlib.php'); require_once($CFG->libdir.'/environmentlib.php'); require_once($CFG->libdir.'/xmlize.php'); require_once($CFG->libdir.'/componentlib.class.php'); require('version.php'); $CFG->target_release = $release; $SESSION = new object(); $SESSION->lang = $CFG->lang; $USER = new object(); $USER->id = 0; $COURSE = new object(); $COURSE->id = 0; $SITE = $COURSE; define('SITEID', 0); $hint_dataroot = ''; $hint_dirroot = ''; $hint_admindir = ''; $hint_database = ''; // Are we in help mode? if (isset($_GET['help'])) { install_print_help_page($_GET['help']); } // send css? if (isset($_GET['css'])) { install_css_styles(); } //first time here? find out suitable dataroot if (is_null($CFG->dataroot)) { $CFG->dataroot = str_replace('\\', '/', dirname(dirname(__FILE__)).'/moodledata'); $i = 0; //safety check - dirname might return some unexpected results while(is_dataroot_insecure()) { $parrent = dirname($CFG->dataroot); $i++; if ($parrent == '/' or $parrent == '.' or preg_match('/^[a-z]:\\\?$/i', $parrent) or ($i > 100)) { $CFG->dataroot = ''; //can not find secure location for dataroot break; } $CFG->dataroot = dirname($parrent).'/moodledata'; } $config->dataroot = $CFG->dataroot; $config->stage = INSTALL_WELCOME; } // now let's do the stage work if ($config->stage < INSTALL_WELCOME) { $config->stage = INSTALL_WELCOME; } if ($config->stage > INSTALL_SAVE) { $config->stage = INSTALL_SAVE; } if ($config->stage == INSTALL_SAVE) { $database = moodle_database::get_driver_instance($config->dbtype, 'native'); if (!$database->driver_installed()) { $config->stage = INSTALL_DATABASETYPE; } else { if (function_exists('distro_pre_create_db')) { // Hook for distros needing to do something before DB creation $distro = distro_pre_create_db($database, $config->dbhost, $config->dbuser, $config->dbpass, $config->dbname, $config->prefix, array('dbpersit'=>0, 'dbsocket'=>$config->dbsocket), $distro); } $hint_database = install_db_validate($database, $config->dbhost, $config->dbuser, $config->dbpass, $config->dbname, $config->prefix, array('dbpersit'=>0, 'dbsocket'=>$config->dbsocket)); if ($hint_database === '') { // extra hackery needed for symbolic link support if ($CFG->dirroot !== $config->dirroot) { $CFG->dirroot = $config->dirroot; $userealpath = true; } else { $userealpath = false; } $configphp = install_generate_configphp($database, $CFG, $userealpath); umask(0137); if (($fh = @fopen($configfile, 'w')) !== false) { fwrite($fh, $configphp); fclose($fh); } if (file_exists($configfile)) { // config created, let's continue! redirect("$CFG->wwwroot/$config->admin/index.php?lang=$config->lang"); } install_print_header($config, 'config.php', get_string('configurationcompletehead', 'install'), get_string('configurationcompletesub', 'install').get_string('configfilenotwritten', 'install')); echo '
'; echo p($configphp); echo '