Commit 3b5ff37f authored by Petr Skoda's avatar Petr Skoda
Browse files

MDL-22546 removing dirroot from the config.php - this should finally solve the...

MDL-22546 removing dirroot from the config.php - this should finally solve the symbolic links issues because we know 100% what should be in $CFG->dirroot once we get into lib/setup.php, it is being initialised there automatically instead + more robust handling of dataroot + simplified config-dist.php and installer; the $CFG->admin is now visible only if admin directory can not be found; please note the old config.php's are still going to work, if admins remove the dirroot they have to add the __FILE__ into require_once lib/setup.php at the end of old config
parent 0b6dc629
......@@ -110,7 +110,7 @@ if (version_compare(phpversion(), "5.2.8") < 0) {
// set up configuration
$CFG = new stdClass();
$CFG->lang = 'en';
$CFG->dirroot = str_replace('\\', '/', dirname(dirname(dirname(__FILE__)))); // Fix for win32
$CFG->dirroot = dirname(dirname(dirname(__FILE__)));
$CFG->libdir = "$CFG->dirroot/lib";
$CFG->wwwroot = "http://localhost";
$CFG->httpswwwroot = $CFG->wwwroot;
......
......@@ -197,32 +197,6 @@ class problem_base {
}
}
class problem_000001 extends problem_base {
function title() {
return 'Invalid value for $CFG->dirroot';
}
function exists() {
global $CFG;
$dirroot = dirname(realpath('../index.php'));
if (!empty($dirroot) && $dirroot != $CFG->dirroot) {
return true;
}
return false;
}
function severity() {
return SEVERITY_CRITICAL;
}
function description() {
global $CFG;
return 'Your <strong>config.php</strong> file contains the setting <strong>$CFG-&gt;dirroot = "'.$CFG->dirroot.'"</strong>, which is incorrect. Unless you correct this problem, Moodle will not function correctly, if at all.';
}
function solution() {
global $CFG;
$dirroot = dirname(realpath('../index.php'));
return 'You need to edit your <strong>config.php</strong> file. Find the line which reads <pre>$CFG->dirroot = \''.$CFG->dirroot.'\';</pre> and change it to read <pre>$CFG->dirroot = \''.$dirroot.'\'</pre>';
}
}
class problem_000002 extends problem_base {
function title() {
return 'Extra characters at the end of config.php or other library function';
......
......@@ -74,14 +74,6 @@ if (is_float_problem()) {
print_error('phpfloatproblem', 'admin', '', $documentationlink);
}
// Check settings in config.php
$dirroot = dirname(realpath('../index.php'));
// Check correct dirroot, ignoring slashes (though should be always forward slashes). MDL-18195
if (!empty($dirroot) and str_replace('\\', '/', $dirroot) != str_replace('\\', '/', $CFG->dirroot)) {
print_error('fixsetting', 'debug', '', (object)array('current'=>$CFG->dirroot, 'found'=>str_replace('\\', '/', $dirroot)));
}
// Set some necessary variables during set-up to avoid PHP warnings later on this page
if (!isset($CFG->framename)) {
$CFG->framename = '_top';
......
......@@ -59,7 +59,7 @@ $CFG->dboptions = array(
//=========================================================================
// 1.5. SECRET PASSWORD SALT
// 2. SECRET PASSWORD SALT
//=========================================================================
// User password salt is very important security feature, it is created
// automatically in installer, you have to uncomment and modify value
......@@ -80,7 +80,7 @@ $CFG->dboptions = array(
//=========================================================================
// 2. WEB SITE LOCATION
// 3. WEB SITE LOCATION
//=========================================================================
// Now you need to tell Moodle where it is located. Specify the full
// web address to where moodle has been installed. If your web site
......@@ -93,19 +93,6 @@ $CFG->dboptions = array(
$CFG->wwwroot = 'http://example.com/moodle';
//=========================================================================
// 3. SERVER FILES LOCATION
//=========================================================================
// Next, specify the full OS directory path to this same location
// Make sure the upper/lower case is correct. Some examples:
//
// $CFG->dirroot = 'C:\program files\easyphp\www\moodle'; // Windows
// $CFG->dirroot = '/var/www/html/moodle'; // Redhat Linux
// $CFG->dirroot = '/home/example/public_html/moodle'; // Cpanel host
$CFG->dirroot = '/home/example/public_html/moodle';
//=========================================================================
// 4. DATA FILES LOCATION
//=========================================================================
......@@ -419,24 +406,8 @@ $CFG->admin = 'admin';
//=========================================================================
// ALL DONE! To continue installation, visit your main page with a browser
//=========================================================================
if ($CFG->wwwroot == 'http://example.com/moodle') {
echo "<p>Error detected in configuration file</p>";
echo "<p>Your server address can not be: \$CFG->wwwroot = 'http://example.com/moodle';</p>";
die;
}
if (file_exists("$CFG->dirroot/lib/setup.php")) { // Do not edit
include_once("$CFG->dirroot/lib/setup.php");
} else {
if ($CFG->dirroot == dirname(__FILE__)) {
echo "<p>Could not find this file: $CFG->dirroot/lib/setup.php</p>";
echo "<p>Are you sure all your files have been uploaded?</p>";
} else {
echo "<p>Error detected in config.php</p>";
echo "<p>Error in: \$CFG->dirroot = '$CFG->dirroot';</p>";
echo "<p>Try this: \$CFG->dirroot = '".dirname(__FILE__)."';</p>";
}
die;
}
require_once(dirname(_FILE_) . '/lib/setup.php'); // Do not edit
// There is no php closing tag in this file,
// it is intentional because it prevents trailing whitespace problems!
......@@ -116,7 +116,6 @@ if (!empty($_POST)) {
$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']);
......@@ -132,7 +131,6 @@ if (!empty($_POST)) {
$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
......@@ -141,7 +139,7 @@ if (!empty($_POST)) {
// 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->dirroot = dirname(__FILE__);
$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;
......@@ -203,7 +201,6 @@ $SITE = $COURSE;
define('SITEID', 0);
$hint_dataroot = '';
$hint_dirroot = '';
$hint_admindir = '';
$hint_database = '';
......@@ -219,7 +216,7 @@ if (isset($_GET['css'])) {
//first time here? find out suitable dataroot
if (is_null($CFG->dataroot)) {
$CFG->dataroot = str_replace('\\', '/', dirname(dirname(__FILE__)).'/moodledata');
$CFG->dataroot = dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR.'moodledata';
$i = 0; //safety check - dirname might return some unexpected results
while(is_dataroot_insecure()) {
......@@ -229,7 +226,7 @@ if (is_null($CFG->dataroot)) {
$CFG->dataroot = ''; //can not find secure location for dataroot
break;
}
$CFG->dataroot = dirname($parrent).'/moodledata';
$CFG->dataroot = dirname($parrent).DIRECTORY_SEPARATOR.'moodledata';
}
$config->dataroot = $CFG->dataroot;
$config->stage = INSTALL_WELCOME;
......@@ -258,14 +255,7 @@ if ($config->stage == INSTALL_SAVE) {
$hint_database = install_db_validate($database, $config->dbhost, $config->dbuser, $config->dbpass, $config->dbname, $config->prefix, array('dbpersist'=>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);
$configphp = install_generate_configphp($database, $CFG);
umask(0137);
if (($fh = @fopen($configfile, 'w')) !== false) {
......@@ -324,12 +314,7 @@ if ($config->stage == INSTALL_DOWNLOADLANG) {
$config->stage = INSTALL_PATHS;
}
if ($config->dirroot === '' or !file_exists($config->dirroot)) {
$hint_dirroot = get_string('pathswrongdirroot', 'install');
$config->stage = INSTALL_PATHS;
}
if ($config->admin === '' or !file_exists($config->dirroot.'/'.$config->admin.'/environment.xml')) {
if ($config->admin === '' or !file_exists($CFG->dirroot.'/'.$config->admin.'/environment.xml')) {
$hint_admindir = get_string('pathswrongadmindir', 'install');
$config->stage = INSTALL_PATHS;
}
......@@ -534,13 +519,15 @@ if ($config->stage == INSTALL_ENVIRONMENT or $config->stage == INSTALL_PATHS) {
if ($config->stage == INSTALL_PATHS) {
$paths = array('wwwroot' => get_string('wwwroot', 'install'),
'dirroot' => get_string('dirroot', 'install'),
'dataroot' => get_string('dataroot', 'install'),
'admindir' => get_string('admindirname', 'install'));
'dataroot' => get_string('dataroot', 'install'));
$sub = '<dl>';
foreach ($paths as $path=>$name) {
$sub .= '<dt>'.$name.'</dt><dd>'.get_string('pathssub'.$path, 'install').'</dd>';
}
if (!file_exists("$CFG->dirroot/admin/environment.xml")) {
$sub .= '<dt>'.get_string('admindirname', 'install').'</dt><dd>'.get_string('pathssubadmindir', 'install').'</dd>';
}
$sub .= '</dl>';
install_print_header($config, get_string('paths', 'install'), get_string('pathshead', 'install'), $sub);
......@@ -556,10 +543,7 @@ if ($config->stage == INSTALL_PATHS) {
echo '</div>';
echo '<div class="formrow"><label for="id_dirroot" class="formlabel">'.$paths['dirroot'].'</label>';
echo '<input id="id_dirroot" name="dirroot" type="text" value="'.s($config->dirroot).'" size="45"class="forminput" />';
if ($hint_dirroot !== '') {
echo '<div class="hint">'.$hint_dirroot.'</div>';
}
echo '<input id="id_dirroot" name="dirroot" type="text" value="'.s($CFG->dirroot).'" disabled="disabled" size="45"class="forminput" />';
echo '</div>';
echo '<div class="formrow"><label for="id_dataroot" class="formlabel">'.$paths['dataroot'].'</label>';
......@@ -570,17 +554,14 @@ if ($config->stage == INSTALL_PATHS) {
echo '</div>';
if (file_exists("$CFG->dirroot/admin/environment.xml")) {
$disabled = 'disabled="disabled"';
} else {
$disabled = '';
}
echo '<div class="formrow"><label for="id_admin" class="formlabel">'.$paths['admindir'].'</label>';
echo '<input id="id_admin" name="admin" type="text" value="'.s($config->admin).'" '.$disabled.' size="10" class="forminput" />';
if ($hint_admindir !== '') {
echo '<div class="hint">'.$hint_admindir.'</div>';
if (!file_exists("$CFG->dirroot/admin/environment.xml")) {
echo '<div class="formrow"><label for="id_admin" class="formlabel">'.$paths['admindir'].'</label>';
echo '<input id="id_admin" name="admin" type="text" value="'.s($config->admin).'" size="10" class="forminput" />';
if ($hint_admindir !== '') {
echo '<div class="hint">'.$hint_admindir.'</div>';
}
echo '</div>';
}
echo '</div>';
echo '</div>';
......
......@@ -33,7 +33,6 @@ $string['cannotsetuptable'] = '{$a} tables could NOT be set up successfully!';
$string['codingerror'] = 'Coding error detected, it must be fixed by a programmer: {$a}';
$string['configmoodle'] = 'Moodle has not been configured yet. You need to edit config.php first.';
$string['erroroccur'] = 'An error has occurred during this process';
$string['fixsetting'] = 'Please fix your settings in config.php: <p>You have:</p> <p>$CFG->dirroot = \'{$a->current}\';</p> <p>but it should be:</p> <p>$CFG->dirroot = \'{$a->found}\';</p>';
$string['invalidarraysize'] = 'Incorrect size of arrays in params of {$a}';
$string['invalideventdata'] = 'Incorrect eventadata submitted: {$a}';
$string['invalidparameter'] = 'Invalid parameter value detected, execution can not continue.';
......
......@@ -313,11 +313,12 @@ control panel or something. Unfortunately this conflicts with the standard loca
renaming the admin directory in your installation, and putting that new name here. For example: <em>moodleadmin</em>. This will fix admin links in Moodle.';
$string['pathssubdataroot'] = 'You need a place where Moodle can save uploaded files. This directory should be readable AND WRITEABLE by the web server user
(usually \'nobody\' or \'apache\'), but it must not be accessible directly via the web. The installer will try to create it if doesn\'t exist.';
$string['pathssubdirroot'] = 'Full directory path to moodle installation. Change only if you need to use symbolic links.';
$string['pathssubdirroot'] = 'Full directory path to moodle installation.';
$string['pathssubwwwroot'] = 'Full web address where moodle will be accessed.
It\'s not possible to access Moodle using multiple addresses.
If your site has multiple public addresses you must setup permanent redirects on all of them except this one.
If your site is accessible both from intranet and Internet use the public address here and setup DNS so that the inranet users may use the public adress too.';
If your site is accessible both from intranet and Internet use the public address here and setup DNS so that the intranet users may use the public address too.
If the address is not correct please change the URL in your browser to restart installation with a different value.';
$string['pathsunsecuredataroot'] = 'Dataroot location is not secure';
$string['pathswrongadmindir'] = 'Admin directory does not exist';
$string['pathswrongdirroot'] = 'Incorrect dirroot localtion';
......
......@@ -130,10 +130,9 @@ function install_db_validate($database, $dbhost, $dbuser, $dbpass, $dbname, $pre
*
* @param moodle_database $database database instance
* @param object $cfg copy of $CFG
* @param bool $userealpath allows symbolic links in dirroot
* @return string
*/
function install_generate_configphp($database, $cfg, $userealpath=false) {
function install_generate_configphp($database, $cfg) {
$configphp = '<?php // Moodle configuration file' . PHP_EOL . PHP_EOL;
$configphp .= 'unset($CFG);' . PHP_EOL;
......@@ -149,19 +148,7 @@ function install_generate_configphp($database, $cfg, $userealpath=false) {
$configphp .= '$CFG->wwwroot = '.var_export($cfg->wwwroot, true) . ';' . PHP_EOL ;
if ($userealpath) {
$dirroot = str_replace('\\', '/', $cfg->dirroot); // win32 fix
$dirroot = rtrim($dirroot, '/'); // no trailing /
$configphp .= '$CFG->dirroot = realpath('.var_export($dirroot, true).');' . PHP_EOL; // fix for sym links
} else {
$dirroot = str_replace('\\', '/', $cfg->dirroot); // win32 fix
$dirroot = rtrim($dirroot, '/'); // no trailing /
$configphp .= '$CFG->dirroot = '.var_export($dirroot, true) . ';' . PHP_EOL;
}
$dataroot = str_replace('\\', '/', $cfg->dataroot); // win32 fix
$dataroot = rtrim($dataroot, '/'); // no trailing /
$configphp .= '$CFG->dataroot = '.var_export($dataroot, true) . ';' . PHP_EOL;
$configphp .= '$CFG->dataroot = '.var_export($cfg->dataroot, true) . ';' . PHP_EOL;
$configphp .= '$CFG->admin = '.var_export($cfg->admin, true) . ';' . PHP_EOL . PHP_EOL;
......@@ -174,7 +161,7 @@ function install_generate_configphp($database, $cfg, $userealpath=false) {
$configphp .= '$CFG->passwordsaltmain = '.var_export(complex_random_string(), true) . ';' . PHP_EOL . PHP_EOL;
$configphp .= 'require_once("$CFG->dirroot/lib/setup.php");' . PHP_EOL . PHP_EOL;
$configphp .= 'require_once(dirname(__FILE__) . \'/lib/setup.php\');' . PHP_EOL . PHP_EOL;
$configphp .= '// There is no php closing tag in this file,' . PHP_EOL;
$configphp .= '// it is intentional because it prevents trailing whitespace problems!' . PHP_EOL;
......
......@@ -31,22 +31,88 @@
* are set in config.php, and the rest are loaded from the config table.
*
* Some typical settings in the $CFG global:
* - $CFG->wwwroot - Path to moodle index directory in url format.
* - $CFG->dataroot - Path to moodle index directory on server's filesystem.
* - $CFG->libdir - Path to moodle's library folder on server's filesystem.
* - $CFG->wwwroot - Path to moodle index directory in url format.
* - $CFG->dataroot - Path to moodle data files directory on server's filesystem.
* - $CFG->dirroot - Path to moodle's library folder on server's filesystem.
* - $CFG->libdir - Path to moodle's library folder on server's filesystem.
*
* @global object $CFG
* @name $CFG
*/
global $CFG;
// We can detect real dirroot path reliably since PHP 4.0.2,
// it can not be anything else, there is no point in having this in config.php
$CFG->dirroot = dirname(dirname(__FILE__));
// Normalise dataroot - we do not want any symbolic links, trailing / or any other weirdness there
if (!isset($CFG->dataroot)) {
header($_SERVER['SERVER_PROTOCOL'] . ' 503 Service Unavailable');
echo('Fatal: $CFG->dataroot is not configured! Exiting.');
exit(1);
}
$CFG->dataroot = realpath($CFG->dataroot);
if ($CFG->dataroot === false) {
header($_SERVER['SERVER_PROTOCOL'] . ' 503 Service Unavailable');
echo('Fatal: $CFG->dataroot is not configured properly! Exiting.');
exit(1);
}
// wwwroot is mandatory
if (!isset($CFG->wwwroot) or $CFG->wwwroot === 'http://example.com/moodle') {
// trigger_error() is not correct here, no need to log this
header($_SERVER['SERVER_PROTOCOL'] . ' 503 Service Unavailable');
echo('Fatal: $CFG->wwwroot is not configured! Exiting.');
exit(1);
}
// Define admin directory
if (!isset($CFG->admin)) { // Just in case it isn't defined in config.php
$CFG->admin = 'admin'; // This is relative to the wwwroot and dirroot
}
// Set up some paths.
$CFG->libdir = $CFG->dirroot .'/lib';
// The current directory in PHP version 4.3.0 and above isn't necessarily the
// directory of the script when run from the command line. The require_once()
// would fail, so we'll have to chdir()
if (!isset($_SERVER['REMOTE_ADDR']) && isset($_SERVER['argv'][0])) {
chdir(dirname($_SERVER['argv'][0]));
}
// sometimes default PHP settings are borked on shared hosting servers, I wonder why they have to do that??
@ini_set('precision', 14); // needed for upgrades and gradebook
// Scripts may request no debug and error messages in output
// please note it must be defined before including the config.php script
// and in some cases you also need to set custom default exception handler
if (!defined('NO_DEBUG_DISPLAY')) {
define('NO_DEBUG_DISPLAY', false);
}
// Detect CLI scripts - CLI scripts are executed from command line, do not have session and we do not want HTML in output
// In your new CLI scripts just add: if (isset($_SERVER['REMOTE_ADDR'])) {die;} before requiring config.php.
if (!defined('CLI_SCRIPT')) {
// CLI_SCRIPT is defined in 'fake' CLI script /admin/cron.php, do not abuse this elsewhere!
if (isset($_SERVER['REMOTE_ADDR'])) {
define('CLI_SCRIPT', false);
} else {
/** @ignore */
define('CLI_SCRIPT', true);
}
}
// Detect ajax scripts - they are similar to CLI because we can not redirect, output html, etc.
if (!defined('AJAX_SCRIPT')) {
define('AJAX_SCRIPT', false);
}
// exact version of currently used yui2 and 3 library
$CFG->yui2version = '2.8.1';
$CFG->yui3version = '3.1.1';
// special support for highly optimised scripts that do not need libraries and DB connection
if (defined('ABORT_AFTER_CONFIG')) {
if (!defined('ABORT_AFTER_CONFIG_CANCEL')) {
......@@ -182,46 +248,6 @@ global $FULLSCRIPT;
*/
global $SCRIPT;
// Scripts may request no debug and error messages in output
// please note it must be defined before including the config.php script
// and in some cases you also need to set custom default exception handler
if (!defined('NO_DEBUG_DISPLAY')) {
define('NO_DEBUG_DISPLAY', false);
}
// wwwroot is mandatory
if (!isset($CFG->wwwroot)) {
// trigger_error() is not correct here, no need to log this
header($_SERVER['SERVER_PROTOCOL'] . ' 503 Service Unavailable');
echo('Fatal: $CFG->wwwroot is not configured! Exiting.');
exit(1);
}
// Detect CLI scripts - CLI scripts are executed from command line, do not have session and we do not want HTML in output
if (!defined('CLI_SCRIPT')) { // CLI_SCRIPT might be defined in 'fake' CLI scripts like admin/cron.php
if (isset($_SERVER['REMOTE_ADDR'])) {
define('CLI_SCRIPT', false);
} else {
/** @ignore */
define('CLI_SCRIPT', true);
}
}
// Detect ajax scripts - they are similar to CLI because we can not redirect, output html, etc.
if (!defined('AJAX_SCRIPT')) {
define('AJAX_SCRIPT', false);
}
// sometimes default PHP settings are borked on shared hosting servers, I wonder why they have to do that??
@ini_set('precision', 14); // needed for upgrades and gradebook
// The current directory in PHP version 4.3.0 and above isn't necessarily the
// directory of the script when run from the command line. The require_once()
// would fail, so we'll have to chdir()
if (!isset($_SERVER['REMOTE_ADDR']) && isset($_SERVER['argv'][0])) {
chdir(dirname($_SERVER['argv'][0]));
}
// Store settings from config.php in array in $CFG - we can use it later to detect problems and overrides
$CFG->config_php_settings = (array)$CFG;
// Forced plugin settings override values from config_plugins table
......@@ -255,11 +281,6 @@ if (!empty($_SERVER['HTTP_X_moz']) && $_SERVER['HTTP_X_moz'] === 'prefetch'){
exit(1);
}
// Define admin directory
if (!isset($CFG->admin)) { // Just in case it isn't defined in config.php
$CFG->admin = 'admin'; // This is relative to the wwwroot and dirroot
}
if (!isset($CFG->prefix)) { // Just in case it isn't defined in config.php
$CFG->prefix = '';
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment