Skip to content

Commit

Permalink
MDL-22546 removing dirroot from the config.php - this should finally …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
skodak committed May 21, 2010
1 parent 0b6dc62 commit 3b5ff37
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 171 deletions.
2 changes: 1 addition & 1 deletion admin/cli/install.php
Expand Up @@ -110,7 +110,7 @@
// 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;
Expand Down
26 changes: 0 additions & 26 deletions admin/health.php
Expand Up @@ -197,32 +197,6 @@ function solution() {
}
}

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';
Expand Down
8 changes: 0 additions & 8 deletions admin/index.php
Expand Up @@ -74,14 +74,6 @@
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';
Expand Down
37 changes: 4 additions & 33 deletions config-dist.php
Expand Up @@ -59,7 +59,7 @@


//=========================================================================
// 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
Expand All @@ -80,7 +80,7 @@


//=========================================================================
// 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
Expand All @@ -93,19 +93,6 @@
$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
//=========================================================================
Expand Down Expand Up @@ -419,24 +406,8 @@
//=========================================================================
// 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!
53 changes: 17 additions & 36 deletions install.php
Expand Up @@ -116,7 +116,6 @@
$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']);
Expand All @@ -132,7 +131,6 @@
$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
Expand All @@ -141,7 +139,7 @@
// 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;
Expand Down Expand Up @@ -203,7 +201,6 @@
define('SITEID', 0);

$hint_dataroot = '';
$hint_dirroot = '';
$hint_admindir = '';
$hint_database = '';

Expand All @@ -219,7 +216,7 @@

//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()) {
Expand All @@ -229,7 +226,7 @@
$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;
Expand Down Expand Up @@ -258,14 +255,7 @@
$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) {
Expand Down Expand Up @@ -324,12 +314,7 @@
$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;
}
Expand Down Expand Up @@ -534,13 +519,15 @@
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);
Expand All @@ -556,10 +543,7 @@
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>';
Expand All @@ -570,17 +554,14 @@
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>';

Expand Down
1 change: 0 additions & 1 deletion lang/en/debug.php
Expand Up @@ -33,7 +33,6 @@
$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.';
Expand Down
5 changes: 3 additions & 2 deletions lang/en/install.php
Expand Up @@ -313,11 +313,12 @@
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';
Expand Down
19 changes: 3 additions & 16 deletions lib/installlib.php
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -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;

Expand Down

0 comments on commit 3b5ff37

Please sign in to comment.