From 8b5b10281c789fde79a391f3079264452321a16e Mon Sep 17 00:00:00 2001 From: moodler Date: Thu, 12 Aug 2004 15:53:32 +0000 Subject: [PATCH] New automatic installation script! No need to make config.php anymore! It's rough but it works. I will be doing lots of work on making it slicker so don't translate the strings just yet. --- index.php | 7 +- install.php | 523 ++++++++++++++++++++++++++++++++++++++++++++ lang/en/install.php | 56 +++++ 3 files changed, 585 insertions(+), 1 deletion(-) create mode 100644 install.php create mode 100755 lang/en/install.php diff --git a/index.php b/index.php index af08858d5e..c1e5cefe8f 100644 --- a/index.php +++ b/index.php @@ -1,7 +1,12 @@ lang = (!empty($_POST['language'])) ? $_POST['language'] : $INSTALL['language']; +$CFG->dirroot = $INSTALL['dirroot']; +$CFG->dataroot = $INSTALL['dataroot']; +$CFG->directorypermissions = 0777; + + +require_once('./lib/moodlelib.php'); +require_once('./lib/weblib.php'); +require_once('./lib/adodb/adodb.inc.php'); + + +/// guess the www root +if ($INSTALL['wwwroot'] == '') { + list($INSTALL['wwwroot'], $xtra) = explode('/install.php', qualified_me()); +} + +$stagetext = array(1 => get_string('chooselanguage', 'install'), + get_string('directorysettings', 'install'), + get_string('databasesettings', 'install'), + get_string('admindirsetting', 'install'), + get_string('configurationcomplete', 'install') + ); + + +//==========================================================================// + +/// Was data submitted? +if (!empty($_POST['stage'])) { + + /// Get the stage for which the form was set and the next stage we are going to + + + if ( $goforward = (! empty( $_POST['next'] )) ) { + $nextstage = $_POST['stage'] + 1; + } else { + $nextstage = $_POST['stage'] - 1; + } + + if ($nextstage < 1) $nextstage = 1; + + + /// Store any posted data + foreach ($_POST as $setting=>$value) { + $INSTALL[$setting] = $value; + } + +} else { + + $goforward = true; + $nextstage = 1; + +} + + + +//==========================================================================// + +/// Check the directory settings +if ($INSTALL['stage'] == 2) { + + error_reporting(0); + + /// check wwwroot + if (($fh = @fopen($INSTALL['wwwroot'].'/install.php', 'r')) === false) { + $errormsg = get_string('wwwrooterror', 'install'); + } else { + fclose($fh); + + /// check dirroot + if (($fh = @fopen($INSTALL['dirroot'].'/install.php', 'r')) === false ) { + $CFG->dirroot = dirname(__FILE__); + $INSTALL['dirroot'] = dirname(__FILE__); + $errormsg = get_string('dirrooterror', 'install'); + } else { + fclose($fh); + + $CFG->dirroot = $INSTALL['dirroot']; + + /// check dataroot + $CFG->dataroot = $INSTALL['dataroot']; + if (make_upload_directory('sessions', false) === false ) { + $errormsg = get_string('datarooterror', 'install'); + } + } + } + + + if (!empty($errormsg)) $nextstage = 2; + + error_reporting(7); +} + + + +//==========================================================================// + +/// Check database settings if stage 3 data submitted +/// Try to connect to the database. If that fails then try to create the database +if ($INSTALL['stage'] == 3) { + + if (empty($INSTALL['dbname'])) { + $INSTALL['dbname'] = 'moodle'; + } + + /// different format for postgres7 + if ($INSTALL['dbtype'] == 'postgres7') { + $INSTALL['dbhost'] = "user='{$INSTALL['dbuser']}' password='{$INSTALL['dbpass']}' dbname='{$INSTALL['dbname']}'"; + if ($INSTALL['prefix'] == '') { /// must have a prefix + $INSTALL['prefix'] = 'mdl_'; + } + } + + $db = &ADONewConnection($INSTALL['dbtype']); + + error_reporting(0); // Hide errors + + if (!($dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname']))) { + /// The following doesn't seem to work but we're working on it + /// If you come up with a solution for creating a database in MySQL + /// feel free to put it in and let us know + if ($dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'])) { + switch ($INSTALL['dbtype']) { /// Try to create a database + case 'mysql': + if ($db->Execute("CREATE DATABASE {$INSTALL['dbname']};")) { + $dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname']); + } else { + $errormsg = get_string('dbcreationerror', 'install'); + $nextstage = 3; + } + break; + } + } + } + + error_reporting(7); + + if (($dbconnected === false) and (empty($errormsg)) ) { + $errormsg = get_string('dbconnectionerror', 'install'); + $nextstage = 3; + } +} + + + +//==========================================================================// + +/// If the next stage is admin directory settings OR we have just come from there then +/// check the admin directory. +/// If we can open a file then we know that the admin name is correct. + +if ($nextstage == 4 or $INSTALL['stage'] == 4) { + if (($fh = @fopen($INSTALL['wwwroot'].'/'.$INSTALL['admindirname'].'/site.html', 'r')) !== false) { + $nextstage = ($goforward) ? 5 : 3; + fclose($fh); + } else { + if ($nextstage != 4) { + $errormsg = get_string('admindirerror', 'install'); + $nextstage = 4; + } + } +} + + + +//==========================================================================// + +/// Display or print the data +/// Put the data into a string +/// Try to open config file for writing. +if ($nextstage == 5) { + + $str = 'dbtype = \''.$INSTALL['dbtype']."';\n"; + $str .= '$CFG->dbhost = \''.$INSTALL['dbhost']."';\n"; + if ($INSTALL['dbtype'] == 'mysql') { + $str .= '$CFG->dbname = \''.$INSTALL['dbname']."';\n"; + $str .= '$CFG->dbuser = \''.$INSTALL['dbuser']."';\n"; + $str .= '$CFG->dbpass = \''.$INSTALL['dbpass']."';\n"; + } + $str .= '$CFG->dbpersist = false;'."\n"; + $str .= '$CFG->prefix = \''.$INSTALL['prefix']."';\n"; + $str .= "\n"; + + $str .= '$CFG->wwwroot = \''.$INSTALL['wwwroot']."';\n"; + $str .= '$CFG->dirroot = \''.$INSTALL['dirroot']."';\n"; + $str .= '$CFG->dataroot = \''.$INSTALL['dataroot']."';\n"; + $str .= "\n"; + + $str .= '$CFG->directorypermissions = 0777;'."\n"; + $str .= "\n"; + + $str .= 'require_once("$CFG->dirroot/lib/setup.php");'."\n"; + $str .= '// MAKE SURE WHEN YOU EDIT THIS FILE THAT THERE ARE NO SPACES, BLANK LINES,'."\n"; + $str .= '// RETURNS, OR ANYTHING ELSE AFTER THE TWO CHARACTERS ON THE NEXT LINE.'."\n"; + $str .= '?>'; + + if (( $configsuccess = ($fh = @fopen($configfile, 'w')) ) !== false) { + fwrite($fh, $str); + fclose($fh); + } +} + + + +//==========================================================================// + +?> + + + + + + +Moodle Install + + + + + + + +

MOODLE INSTALL

+ + + + + + + + + +

+ +$errormsg

\n"; + + +if ($nextstage == 5) { + if ($configsuccess) { + echo "

".get_string('configfilewritten', 'install')."

\n"; + } else { + echo "

".get_string('configfilenotwritten', 'install')."

"; + echo "
\n"; + echo "
\n"; + print_object(htmlentities($str)); + echo "
\n"; + echo "
\n"; + } + echo "

(Continue)

\n"; +} else { + $formaction = (isset($_GET['configfile'])) ? "install.php?configfile=".$_GET['configfile'] : "install.php"; + form_table($nextstage, $formaction); +} + +?> + +
+ + + + + + + + + + + + + +\n"; + print_r($object); + echo "\n"; +} + + + +//==========================================================================// + +function form_table($nextstage = 1, $formaction = "install.php") { + global $INSTALL; + + /// standard lines for all forms +?> + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

+ +

+ +

+ +

+ +

+ "mysql", "postgres7" => "postgres7"), 'dbtype', $INSTALL['dbtype'], '') ?> +

+ +

+ +

+ +

+ +

+ +

+ +
+ 1) ? "\n" : " \n" ?> + + \n" : " \n" ?> +
+
+ + + + + + diff --git a/lang/en/install.php b/lang/en/install.php new file mode 100755 index 0000000000..d639a1ca16 --- /dev/null +++ b/lang/en/install.php @@ -0,0 +1,56 @@ +A very few webhosts use /admin as a special URL for you to access a + control panel or something. Unfortunately this conflicts with the + standard location for the Moodle admin pages. You can fix this by + renaming the admin directory in your installation, and putting that + new name here. For example:
moodleadmin
. + This will fix admin links in Moodle.

"; +$string['chooselanguage'] = 'Choose a language'; +$string['configfilenotwritten'] = "The installer script was not able to automatically create a config.php file containing your chosen settings. Please copy the following code into a file named config.php within the root directory of Moodle."; +$string['configfilewritten'] = "config.php has been successfully created"; +$string['configurationcomplete'] = 'Configuration completed'; + +$string['database'] = 'Database'; +$string['databasesettings'] = " +

Now you need to configure the database where most Moodle data + will be stored. This database must already have been created + and a username and password created to access it.

+

Type: mysql or postgres7
+ Host Server: eg localhost or db.isp.com
+ Name: database name, eg moodle
+ User: your database username
+ Password: your database password
+ Tables Prefix: prefix to use for all table names

"; +$string['dataroot'] = 'Data'; +$string['datarooterror'] = "The 'Data' setting is incorrect"; +$string['dbconnectionerror'] = 'Database connection error. Please check your database settings'; +$string['dbcreationerror'] = 'Database creation error. Could not create the given database name with the settings provided'; +$string['dbhost'] = 'Host Server'; +$string['dbpass'] = 'Password'; +$string['dbprefix'] = 'Tables prefix'; +$string['dbtype'] = 'Type'; +$string['directorysettings'] = " +

WWW: + You need to tell Moodle where it is located. Specify the full + web address to where moodle has been installed. If your web site + is accessible via multiple URLs then choose the most natural one + that your students would use. Do not include a trailing slash

+

Directory: + Specify the full OS directory path to this same location + Make sure the upper/lower case is correct

+

Data: + 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 should not be accessible + directly via the web.

"; + +$string['dirroot'] = 'Directory'; +$string['dirrooterror'] = "The 'Directory' setting was incorrect. Try the following setting"; +$string['wwwroot'] = 'WWW'; +$string['wwwrooterror'] = "The 'WWW' setting is incorrect"; + +?> -- 2.39.5