forked from science-ation/science-ation
Add the installer script - currently it only creates the data/config.inc.php database settings - it still needs to create the actual tables.
Add some extra sanity checking to the db updater Add more sanity checking to the common.inc.php
This commit is contained in:
parent
9867b507b2
commit
9604c35f4b
@ -24,6 +24,24 @@
|
||||
<?
|
||||
$sfiabversion=@file("version.txt");
|
||||
$config['version']=$sfiabversion[0];
|
||||
|
||||
//make sure the data subdirectory is writable, if its not, then we're screwed, so make sure it is!
|
||||
if(!is_writable("data"))
|
||||
{
|
||||
echo "<html><head><title>SFIAB ERROR</title></head><body>";
|
||||
echo "<h1>Science Fair In A Box - ERROR</h1>";
|
||||
echo "data/ subdirectory is not writable by the web server";
|
||||
echo "<br>";
|
||||
echo "<h2>Details</h2>";
|
||||
echo "The data/ subdirectory is used to store files uploaded through the SFIAB software. The web server must have write access to this directory in order to function properly. Please contact your system administrator (if you are the system administrator, chown/chmod the data directory appropriately).";
|
||||
echo "<br>";
|
||||
echo "</body></html>";
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//first things first - make sure our DB version matches our CODE version
|
||||
$dbcodeversion=@file("db/db.code.version.txt");
|
||||
$dbdbversion=@file("db/db.db.version.txt");
|
||||
@ -47,11 +65,42 @@ if($dbcodeversion[0]!=$dbdbversion[0])
|
||||
echo "</body></html>";
|
||||
exit;
|
||||
}
|
||||
if(file_exists("data/config.inc.php"))
|
||||
{
|
||||
require_once("data/config.inc.php");
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "<html><head><title>SFIAB</title></head><body>";
|
||||
echo "<h1>Science Fair In A Box - Installation</h1>";
|
||||
echo "It looks like this is a new installation of SFIAB, and the database has not yet been configured. Please choose from the following options: <br />";
|
||||
echo "<br />";
|
||||
echo "<a href=\"install.php\">Proceed with Fresh SFIAB Installation</a>";
|
||||
echo "<br />";
|
||||
echo "</body></html>";
|
||||
exit;
|
||||
}
|
||||
|
||||
require_once("config.inc.php");
|
||||
require_once("committee_auth.php");
|
||||
mysql_connect($DBHOST,$DBUSER,$DBPASS);
|
||||
mysql_select_db($DBNAME);
|
||||
|
||||
if(!mysql_connect($DBHOST,$DBUSER,$DBPASS))
|
||||
{
|
||||
echo "<html><head><title>SFIAB ERROR</title></head><body>";
|
||||
echo "<h1>Science Fair In A Box - ERROR</h1>";
|
||||
echo "Cannot connect to database!";
|
||||
echo "</body></html>";
|
||||
exit;
|
||||
}
|
||||
|
||||
if(!mysql_select_db($DBNAME))
|
||||
{
|
||||
echo "<html><head><title>SFIAB ERROR</title></head><body>";
|
||||
echo "<h1>Science Fair In A Box - ERROR</h1>";
|
||||
echo "Cannot select database!";
|
||||
echo "</body></html>";
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
session_start();
|
||||
|
||||
|
@ -32,6 +32,7 @@ if($dbcodeversion && $dbdbversion)
|
||||
else if($dbcodeversion<$dbdbversion)
|
||||
{
|
||||
echo "ERROR: dbcodeversion<dbdbversion ($dbcodeversion<$dbdbversion). This should not happen!";
|
||||
exit;
|
||||
|
||||
}
|
||||
else if($dbcodeversion>$dbdbversion)
|
||||
@ -39,10 +40,15 @@ if($dbcodeversion && $dbdbversion)
|
||||
echo "DB update requirements detected\n";
|
||||
echo "Current DB Version: $dbdbversion\n";
|
||||
echo "Current CODE Version: $dbcodeversion\n";
|
||||
//first, make sure we have write access to the db.db.version.txt
|
||||
//otherwise, we will not be able to save the new version number
|
||||
//which would screw things up.
|
||||
if(is_writable("db.db.version.txt"))
|
||||
{
|
||||
echo "Updating database from $dbdbversion to $dbcodeversion\n";
|
||||
//include the config.inc.php
|
||||
//so we have the db connection info
|
||||
require("../config.inc.php");
|
||||
require("../data/config.inc.php");
|
||||
|
||||
for($ver=$dbdbversion+1;$ver<=$dbcodeversion;$ver++)
|
||||
{
|
||||
@ -63,6 +69,11 @@ if($dbcodeversion && $dbdbversion)
|
||||
fputs($fp,$dbcodeversion."\n");
|
||||
fclose($fp);
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "ERROR: cannot perform upgrade. db.db.version.txt is not writeable";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
|
110
install.php
Normal file
110
install.php
Normal file
@ -0,0 +1,110 @@
|
||||
<?
|
||||
/*
|
||||
This file is part of the 'Science Fair In A Box' project
|
||||
SFIAB Website: http://www.sfiab.ca
|
||||
|
||||
Copyright (C) 2005 Sci-Tech Ontario Inc <info@scitechontario.org>
|
||||
Copyright (C) 2005 James Grant <james@lightbox.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public
|
||||
License as published by the Free Software Foundation, version 2.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; see the file COPYING. If not, write to
|
||||
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
echo "<?xml version=\"1.0\" encoding=\"iso-8859-1\" ?>\n";
|
||||
?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" >
|
||||
<head><title>SFIAB Installation</title>
|
||||
<link rel="stylesheet" href="sfiab.css" type="text/css" />
|
||||
</head>
|
||||
<body>
|
||||
<?
|
||||
if(file_exists("data/config.inc.php"))
|
||||
{
|
||||
echo "<div class=\"error\">SFIAB is already installed</div>";
|
||||
echo "</body></html>";
|
||||
exit;
|
||||
}
|
||||
?>
|
||||
|
||||
<h1>SFIAB Installation</h1>
|
||||
|
||||
<?
|
||||
$showform=true;
|
||||
|
||||
if($_POST['dbhost'] && $_POST['dbname'] && $_POST['dbuser'] && $_POST['dbpass'])
|
||||
{
|
||||
if(@mysql_connect($_POST['dbhost'],$_POST['dbuser'],$_POST['dbpass']))
|
||||
{
|
||||
if(mysql_select_db($_POST['dbname']))
|
||||
{
|
||||
$showform=false;
|
||||
echo "<div class=\"happy\">Database connection successful!</div>";
|
||||
echo "<br />";
|
||||
echo "Storing database connection information... ";
|
||||
if($fp=fopen("data/config.inc.php","w"))
|
||||
{
|
||||
fputs($fp,"<?\n");
|
||||
fputs($fp,"\$DBHOST=\"".$_POST['dbhost']."\";\n");
|
||||
fputs($fp,"\$DBUSER=\"".$_POST['dbuser']."\";\n");
|
||||
fputs($fp,"\$DBPASS=\"".$_POST['dbpass']."\";\n");
|
||||
fputs($fp,"\$DBNAME=\"".$_POST['dbname']."\";\n");
|
||||
fputs($fp,"?>\n");
|
||||
fclose($fp);
|
||||
echo "<b>Done!</b>";
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "<div class=\"error\">Cannot write to data/config.inc.php. Make sure the web server has write access to the data/ subdirectory</div>";
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "<div class=\"error\">Connected, but cannot select database. Make sure Database Name is correct, and that the user '".$_POST['dbuser']."' has access to it</div>";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "<div class=\"error\">Cannot connect to database. Make sure Host, User and Pass are correct</div>";
|
||||
}
|
||||
echo "<br />";
|
||||
}
|
||||
|
||||
|
||||
if($showform)
|
||||
{
|
||||
?>
|
||||
SFIAB requires a MySQL database to store all of its information. Please enter your MySQL database connection info for your database to continue. The database must already exist and the user/password you specify must have access to the database.
|
||||
|
||||
<br />
|
||||
<br />
|
||||
<form method="post" action="install.php">
|
||||
<table class="summarytable">
|
||||
<tr><th>Database Host</th><td><input type="text" name="dbhost" value="localhost"></td></tr>
|
||||
<tr><th>Database User</th><td><input type="text" name="dbuser" value=""></td></tr>
|
||||
<tr><th>Database Pass</th><td><input type="text" name="dbpass" value=""></td></tr>
|
||||
<tr><th>Database Name</th><td><input type="text" name="dbname" value="sfiab"></td></tr>
|
||||
<tr><td colspan=2 align=center><input type="submit" value="Connect to database"></td></tr>
|
||||
</table>
|
||||
</form>
|
||||
|
||||
<?
|
||||
}
|
||||
?>
|
||||
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user