From 51e3e0b9a1b845a4325db0cddaa97926177e5425 Mon Sep 17 00:00:00 2001 From: moodler Date: Thu, 19 Aug 2004 08:53:23 +0000 Subject: [PATCH] Updated ... unfortuntely some of the fixes are the same as PJs but there is also lots of other stuff too. --- install.php | 259 +++++++++++++++++++++++++++------------------------- 1 file changed, 137 insertions(+), 122 deletions(-) diff --git a/install.php b/install.php index 1f00bdd14e..59a8dff759 100644 --- a/install.php +++ b/install.php @@ -3,9 +3,9 @@ /// If config.php exists already then we are not needed. -if (file_exists('./config.php')) { +if (file_exists('./config.php')) { header('Location: index.php'); - die(); + die; } else { $configfile = './config.php'; } @@ -103,24 +103,20 @@ if (isset($_GET['help'])) { } + //==========================================================================// -/// Any special action we need to take? +/// Are we in config download mode? -if(isset($_POST['specialaction'])) { - switch($_POST['specialaction']) { - case 'downloadconfig': - $str = generate_config_php(); - header('Content-Type: text/plain'); - header('Content-Disposition: attachment; filename="config.php"'); - header('Content-Length: '.strlen($str)); - header('Connection: Close'); - echo $str; - die(); - break; - } +if (isset($_GET['download'])) { + header("Content-Type: application/download\n"); + header("Content-Disposition: attachment; filename=\"config.php\""); + echo $INSTALL['config']; + exit; } + + //==========================================================================// /// Was data submitted? @@ -135,20 +131,20 @@ if (isset($_POST['stage'])) { } else { $nextstage = $_POST['stage'] - 1; } - + if ($nextstage < 0) $nextstage = 0; - + /// Store any posted data foreach ($_POST as $setting=>$value) { $INSTALL[$setting] = $value; } - + } else { $goforward = true; $nextstage = 0; - + } @@ -160,31 +156,32 @@ if (isset($_POST['stage'])) { if ($INSTALL['stage'] == 2) { error_reporting(0); - - /// check wwwroot - if (($fh = @fopen($INSTALL['wwwroot'].'/install.php', 'r')) === false) { - $errormsg = get_string('wwwrooterror', 'install'); + + + /// 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 dirroot - if (($fh = @fopen($INSTALL['dirroot'].'/install.php', 'r')) === false ) { - $CFG->dirroot = dirname(__FILE__); - $INSTALL['dirroot'] = dirname(__FILE__); - $errormsg = get_string('dirrooterror', 'install'); + /// check wwwroot + if (($fh = @fopen($INSTALL['wwwroot'].'/install.php', 'r')) === false) { + $errormsg = get_string('wwwrooterror', '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; @@ -203,7 +200,7 @@ if ($INSTALL['stage'] == 3) { if (empty($INSTALL['dbname'])) { $INSTALL['dbname'] = 'moodle'; } - + /// different format for postgres7 by socket if ($INSTALL['dbtype'] == 'postgres7' and ($INSTALL['dbhost'] == 'localhost' || $INSTALL['dbhost'] == '127.0.0.1')) { $INSTALL['dbhost'] = "user='{$INSTALL['dbuser']}' password='{$INSTALL['dbpass']}' dbname='{$INSTALL['dbname']}'"; @@ -218,11 +215,11 @@ if ($INSTALL['stage'] == 3) { $db = &ADONewConnection($INSTALL['dbtype']); - error_reporting(0); // Hide errors - + 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 + /// 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 @@ -275,11 +272,43 @@ if ($nextstage == 4 or $INSTALL['stage'] == 4) { /// Try to open config file for writing. if ($nextstage == 5) { + + $str = 'dbtype = \''.$INSTALL['dbtype']."';\r\n"; + $str .= '$CFG->dbhost = \''.$INSTALL['dbhost']."';\r\n"; + if ($INSTALL['dbtype'] == 'mysql') { + $str .= '$CFG->dbname = \''.$INSTALL['dbname']."';\r\n"; + $str .= '$CFG->dbuser = \''.$INSTALL['dbuser']."';\r\n"; + $str .= '$CFG->dbpass = \''.$INSTALL['dbpass']."';\r\n"; + } + $str .= '$CFG->dbpersist = false;'."\r\n"; + $str .= '$CFG->prefix = \''.$INSTALL['prefix']."';\r\n"; + $str .= "\r\n"; + + $str .= '$CFG->wwwroot = \''.$INSTALL['wwwroot']."';\r\n"; + $str .= '$CFG->dirroot = \''.$INSTALL['dirroot']."';\r\n"; + $str .= '$CFG->dataroot = \''.$INSTALL['dataroot']."';\r\n"; + $str .= "\r\n"; + + $str .= '$CFG->directorypermissions = 0777;'."\r\n"; + $str .= "\r\n"; + + $str .= 'require_once("$CFG->dirroot/lib/setup.php");'."\r\n"; + $str .= '// MAKE SURE WHEN YOU EDIT THIS FILE THAT THERE ARE NO SPACES, BLANK LINES,'."\r\n"; + $str .= '// RETURNS, OR ANYTHING ELSE AFTER THE TWO CHARACTERS ON THE NEXT LINE.'."\r\n"; + $str .= '?>'; + if (( $configsuccess = ($fh = @fopen($configfile, 'w')) ) !== false) { - $str = generate_config_php(); fwrite($fh, $str); fclose($fh); } + + $INSTALL['config'] = $str; } @@ -301,13 +330,11 @@ if ($nextstage == 5) { - -
- @@ -330,26 +357,51 @@ if (isset($_GET['help'])) { - + $errormsg

\n"; if ($nextstage == 5) { + $INSTALL['stage'] = 0; + $options = array(); + $options['lang'] = $INSTALL['language']; if ($configsuccess) { echo "

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

\n"; + + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "
  \n"; + print_single_button("index.php", $options, get_string('continue')." »"); + echo "
\n"; + } else { - echo "

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

"; - echo '

'; - echo ''; - echo ''; - echo '

'; + echo "

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

"; + + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "
 \n"; + $installoptions = array(); + $installoptions['download'] = 1; + print_single_button("install.php", $installoptions, get_string('download', 'install')); + echo "\n"; + print_single_button("index.php", $options, get_string('continue')." »"); + echo "
\n"; + echo "
\n"; + echo "
\n"; + print_object(htmlentities($str)); + echo "
\n"; } - $options = array(); - $options['lang'] = $INSTALL['language']; - print_single_button("index.php", $options, get_string('continue')." »"); } else { $formaction = (isset($_GET['configfile'])) ? "install.php?configfile=".$_GET['configfile'] : "install.php"; form_table($nextstage, $formaction); @@ -377,7 +429,7 @@ if ($nextstage == 5) { - - - + + + + \n" : " \n" ?> + 0) ? "\n" : " \n" ?> + + + + \n"; - echo "

$testtext

\n"; + echo "

$testtext

\n"; if ($success) { - echo "

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

\n"; - echo " \n"; + echo "

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

\n"; + echo " \n"; } else { - echo "

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

\n"; - echo ""; - echo "

$errormessage "; - install_helpbutton("install.php?help=$helpfield"); - echo "

\n"; + echo "".get_string('caution', 'install') : "

".get_string('fail', 'install'); + echo "

\n"; + echo ""; + echo "

$errormessage "; + install_helpbutton("install.php?help=$helpfield"); + echo "

\n"; } echo "\n"; return $success; @@ -568,13 +623,12 @@ function install_helpbutton($url, $title='') { echo "onClick=\"return window.open('$url', 'Help', 'menubar=0,location=0,scrollbars,resizable,width=500,height=400')\">"; echo "\n"; } - + //==========================================================================// function print_install_help($help) { - echo "

"; switch ($help) { case 'phpversionhelp': print_string($help, 'install', phpversion()); @@ -585,7 +639,6 @@ function print_install_help($help) { default: print_string($help, 'install'); } - echo "

\n"; } @@ -613,45 +666,6 @@ function check_memory_limit() { return ((int)str_replace('M', '', get_memory_limit()) >= 16); } -//==========================================================================// - -function generate_config_php() { - global $INSTALL; - - $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 .= '?>'; - - return $str; -} - - //==========================================================================// function css_styles() { @@ -660,7 +674,7 @@ function css_styles() {