b2/install.php
2010-02-14 11:40:14 -05:00

525 lines
23 KiB
PHP

<?
/******************************************************************************\
* Copyright (C) 2002 B Squared (b^2) by Josh Sherman <josh@cleancode.org> *
* *
* This script is for [re]installing b^2 on your server. It cannot be called *
* directly, for security purposes, what you will need to do is delete the *
* config.php file, or set the global variable of INSTALLED to 'no'. The *
* installer will prompt you for information, and build your database, and *
* configuration files. I recommend giving this file write access, if not, *
* you will need to upload the config.php file that is generated to the root *
* directory (the directory that this file is in). *
* *
* Last modified : September 25th, 2002 (JJS) *
\******************************************************************************/
/* Load up the language file for the installer */
require("./language/installer.php");
/* This will make sure kid's don't play around with this file */
$file_name = "install.php";
/* Get the negative length of $file_name */
$file_name_length = -(strlen($file_name));
/* Check if the values match, if so, redirect */
if (substr($_SERVER['SCRIPT_NAME'], $file_name_length) == $file_name)
header("Location: ../index.php");
/* Turn off dummy error messages */
define("ADMIN_ERRORS", "yes");
/* Set the step to NULL */
$step = "";
/* Grab the REQUEST_METHOD */
$REQUEST_METHOD = $_SERVER['REQUEST_METHOD'];
/* If the form was POSTed then ... */
if ( $REQUEST_METHOD == "POST" )
{
/* Define constants for the MySQL variables */
define("DB_USER", $_POST['db_user']);
define("DB_PASS", $_POST['db_pass']);
define("DB_NAME", $_POST['db_name']);
define("DB_HOST", $_POST['db_host']);
$table_prefix = $_POST['table_prefix'];
/* Grab the step number */
$step = $_POST['step'];
/* Grab the rest of the variables from the super global, assuming it's step 3 */
if ($step != 3)
{
$board_name = $_POST['board_name'];
$title_image = $_POST['title_image'];
$admin_user = $_POST['admin_user'];
$admin_pass = $_POST['admin_pass'];
$admin_pass2 = $_POST['admin_pass2'];
$admin_email = $_POST['admin_email'];
$forum_name = $_POST['forum_name'];
$forum_desc = $_POST['forum_desc'];
}
/* Define the contents of the config.php file */
$config_file = "<?
/******************************************************************************\
* Copyright (C) 2002 B Squared (b^2) by Josh Sherman <josh@cleancode.org> *
* *
* This script is generated by b^2 upon installing the sofware. It is *
* recommended that you don't edit the file, but if you must, you must. If *
* you wish to perform a clean install, either delete this file, or set the *
* global variable 'INSTALLED' to equal 'no'. *
* *
* Last modified : September 25th, 2002 (JJS) *
\******************************************************************************/
/* Installation status */
define(\"INSTALLED\", \"yes\");
if (INSTALLED == \"yes\")
{
/* Variables used by MySQL */
define(\"DB_USER\", \"" . DB_USER . "\");
define(\"DB_PASS\", \"" . DB_PASS . "\");
define(\"DB_NAME\", \"" . DB_NAME . "\");
define(\"DB_HOST\", \"" . DB_HOST . "\");
/* Prefix for the tables in the database */
define(\"TABLE_PREFIX\", \"" . $table_prefix . "\");
/* Toggle dummy error messages */
define(\"ADMIN_ERRORS\", \"no\");
/* Notify admin on error? */
define(\"NOTIFY_ADMIN\", \"yes\");
/* Administrator's email addy */
define(\"ADMIN_EMAIL\", \"" . $admin_email . "\");
/* Define the language pack to use */
define(\"LANGUAGE\", \"English\");
}
?>";
}
/* Jump to the right step */
switch ($step)
{
/* Default / step 1, display the form for the installer */
default:
case 1:
/* Show the HTML header */
ShowHeader();
echo " <SCRIPT language=\"JavaScript\">\n"
. " function\n"
. " CheckForm()\n"
. " {\n"
. " if (document.installer.board_name.value == '')\n"
. " {\n"
. " alert('The \'Board Name\' field is mandatory!');\n"
. " document.installer.board_name.focus(1);\n"
. " return false;\n"
. " }\n"
. " if (document.installer.db_user.value == '')\n"
. " {\n"
. " alert('The MySQL \'Username\' field is mandatory!');\n"
. " document.installer.db_user.focus(1);\n"
. " return false;\n"
. " }\n"
. " if (document.installer.db_name.value == '')\n"
. " {\n"
. " alert('The MySQL \'Database\' field is mandatory!');\n"
. " document.installer.db_name.focus(1);\n"
. " return false;\n"
. " }\n"
. " if (document.installer.db_host.value == '')\n"
. " {\n"
. " alert('The MySQL \'Hostname\' field is mandatory!\\n\\nOn most systems this will be \'localhost\'.');\n"
. " document.installer.db_host.focus(1);\n"
. " return false;\n"
. " }\n"
. " if (document.installer.table_prefix.value == '')\n"
. " {\n"
. " alert('The \'Table Prefix\' field is mandatory!');\n"
. " document.installer.table_prefix.focus(1);\n"
. " return false;\n"
. " }\n"
. " if (document.installer.admin_user.value == '')\n"
. " {\n"
. " alert('The Admin \'Username\' field is mandatory!');\n"
. " document.installer.admin_user.focus(1);\n"
. " return false;\n"
. " }\n"
. " if (document.installer.admin_pass.value == '')\n"
. " {\n"
. " alert('The Admin \'Password\' field is mandatory!');\n"
. " document.installer.admin_pass.focus(1);\n"
. " return false;\n"
. " }\n"
. " if (document.installer.admin_pass2.value == '')\n"
. " {\n"
. " alert('The Admin \'Confirm Password\' field is mandatory!');\n"
. " document.installer.admin_pass2.focus(1);\n"
. " return false;\n"
. " }\n"
. " if (document.installer.admin_pass.value != document.installer.admin_pass2.value)\n"
. " {\n"
. " alert('The Admin \'Password\' and \'Confirm Password\' fields must match!');\n"
. " document.installer.admin_pass.select();\n"
. " document.installer.admin_pass2.value = '';\n"
. " return false;\n"
. " }\n"
. " if (document.installer.admin_email.value == '')\n"
. " {\n"
. " alert('The Admin \'Email\' field is mandatory!');\n"
. " document.installer.admin_email.focus(1);\n"
. " return false;\n"
. " }\n"
. " if (document.installer.forum_name.value == '')\n"
. " {\n"
. " alert('The Initial Forum \'Name\' field is mandatory!');\n"
. " document.installer.forum_name.focus(1);\n"
. " return false;\n"
. " }\n"
. " if (document.installer.forum_desc.value == '')\n"
. " {\n"
. " alert('The Initial Forum \'Description\' field is mandatory!');\n"
. " document.installer.forum_desc.focus(1);\n"
. " return false;\n"
. " }\n"
. " return true;\n"
. " }\n"
. " </SCRIPT>\n"
. " <FORM method=\"POST\" name=\"installer\" action=\"index.php\">\n"
. " <TABLE width=\"500\" align=\"center\">\n"
. " <TR>\n"
. " <TD colspan=\"2\">" . GENERAL . ":<HR noshade></TD>\n"
. " </TR>\n"
. " <TR>\n"
. " <TD nowrap><B>" . BOARD_NAME . ": </B></TD>\n"
. " <TD align=\"right\"><INPUT type=\"text\" name=\"board_name\" size=\"50\" maxlength=\"64\"></TD>\n"
. " </TR>\n"
. " <TR>\n"
. " <TD nowrap><B>" . TITLE_IMAGE . ": </B></TD>\n"
. " <TD align=\"right\"><INPUT type=\"text\" name=\"title_image\" size=\"50\" maxlength=\"64\"></TD>\n"
. " </TR>\n"
. " <TR>\n"
. " <TD colspan=\"2\"><HR noshade><BR>" . MYSQL . ":<HR noshade></TD>\n"
. " </TR>\n"
. " <TR>\n"
. " <TD nowrap><B>" . USERNAME . ": </B></TD>\n"
. " <TD align=\"right\"><INPUT type=\"text\" name=\"db_user\" size=\"50\"></TD>\n"
. " </TR>\n"
. " <TR>\n"
. " <TD nowrap><B>" . PASSWORD . ": </B></TD>\n"
. " <TD align=\"right\"><INPUT type=\"password\" name=\"db_pass\" size=\"50\"></TD>\n"
. " </TR>\n"
. " <TR>\n"
. " <TD nowrap><B>" . DATABASE . ": </B></TD>\n"
. " <TD align=\"right\"><INPUT type=\"text\" name=\"db_name\" size=\"50\"></TD>\n"
. " </TR>\n"
. " <TR>\n"
. " <TD nowrap><B>" . HOSTNAME . ": </B></TD>\n"
. " <TD align=\"right\"><INPUT type=\"text\" name=\"db_host\" size=\"50\" value=\"localhost\"></TD>\n"
. " </TR>\n"
. " <TR>\n"
. " <TD nowrap><B>" . TABLE_PREFIX . ": </B></TD>\n"
. " <TD align=\"right\"><INPUT type=\"text\" name=\"table_prefix\" size=\"50\" value=\"b2_\"></TD>\n"
. " </TR>\n"
. " <TR>\n"
. " <TD colspan=\"2\"><HR noshade><BR>" . ADMIN . ":<HR noshade></TD>\n"
. " </TR>\n"
. " <TR>\n"
. " <TD nowrap><B>" . USERNAME . ": </B></TD>\n"
. " <TD align=\"right\"><INPUT type=\"text\" name=\"admin_user\" size=\"50\"></TD>\n"
. " </TR>\n"
. " <TR>\n"
. " <TD nowrap><B>" . PASSWORD . ": </B></TD>\n"
. " <TD align=\"right\"><INPUT type=\"password\" name=\"admin_pass\" size=\"50\"></TD>\n"
. " </TR>\n"
. " <TR>\n"
. " <TD nowrap><B>" . CONFIRM_PASSWORD . ": </B></TD>\n"
. " <TD align=\"right\"><INPUT type=\"password\" name=\"admin_pass2\" size=\"50\"></TD>\n"
. " </TR>\n"
. " <TR>\n"
. " <TD nowrap><B>" . EMAIL . ": </B></TD>\n"
. " <TD align=\"right\"><INPUT type=\"text\" name=\"admin_email\" size=\"50\"></TD>\n"
. " </TR>\n"
. " <TR>\n"
. " <TD colspan=\"2\"><HR noshade><BR>" . FORUM . ":<HR noshade></TD>\n"
. " </TR>\n"
. " <TR>\n"
. " <TD nowrap><B>" . NAME . ": </B></TD>\n"
. " <TD align=\"right\"><INPUT type=\"text\" name=\"forum_name\" size=\"50\" value=\"" . FORUM_NAME . "\"></TD>\n"
. " </TR>\n"
. " <TR>\n"
. " <TD nowrap><B>" . DESC . ": </B></TD>\n"
. " <TD align=\"right\"><INPUT type=\"text\" name=\"forum_desc\" size=\"50\" value=\"" . FORUM_DESC . "\"></TD>\n"
. " </TR>\n"
. " <TR>\n"
. " <TD colspan=\"2\" align=\"center\"><HR noshade><BR><INPUT type=\"submit\" name=\"install\" value=\"" . INSTALL_BUTTON . "\" onClick=\"return CheckForm();\"></TD>\n"
. " </TR>\n"
. " </TABLE>\n"
. " <INPUT type=\"hidden\" name=\"step\" value=\"2\">\n"
. " </FORM>\n";
/* Show the HTML Footer */
ShowFooter();
break;
/* Now the user put the info in, why don't we check the MySQL variables to make sure it works? */
case 2:
/* Show the HTML header */
ShowHeader();
/* Connect to the MySQL database */
define("CONNECTION", @mysql_connect(DB_HOST, DB_USER, DB_PASS));
/* If it connects, then proceed to doing the install, if not, tell the user */
if (!CONNECTION)
exit("<CENTER>There was a problem connecting to MySQL.<BR><BR><A href=\"javascript:history.go(-1)\">Previous Page</CENTER>\n");
else
{
/* Create the 'forums' table */
$SQL = "create table " . $table_prefix . "forums
(
forum_id int(10) not null auto_increment,
forum_order int(10) null,
forum_name varchar(64) not null,
forum_desc varchar(255) not null,
primary key(forum_id)
);";
$results = ExeSQL($SQL);
/* Create the 'threads' table */
$SQL = "create table " . $table_prefix . "threads
(
thread_id int(10) not null auto_increment,
thread_title varchar(64) not null,
thread_body text not null,
thread_time timestamp(14) not null,
user_id int(10) not null,
user_ip varchar(15) not null,
forum_id int(10) not null,
primary key(thread_id)
);";
$results = ExeSQL($SQL);
/* Create the 'users' table */
$SQL = "create table " . $table_prefix . "users
(
user_id int(10) not null auto_increment,
user_name varchar(64) not null,
user_email varchar(128) not null,
user_pass varchar(64) not null,
user_location varchar(128) null,
user_occupation varchar(64) null,
user_homepage varchar(128) null,
user_picture varchar(128) null,
user_interests varchar(255) null,
user_aim varchar(16) null,
user_icq varchar(16) null,
user_yahoo varchar(32) null,
user_signature varchar(255) null,
user_usesig int(1) null default '0',
primary key(user_id)
);";
$results = ExeSQL($SQL);
/* Create the 'replies' table */
$SQL = "create table " . $table_prefix . "replies
(
reply_id int(10) not null auto_increment,
reply_body text not null,
reply_time timestamp(14) not null,
user_id int(10) not null,
user_ip varchar(15) not null,
thread_id int(10) not null,
forum_id int(10) not null,
primary key(reply_id)
);";
$results = ExeSQL($SQL);
/* Create the 'moderators' table */
$SQL = "create table " . $table_prefix . "moderators
(
moderator_id int(10) not null auto_increment,
user_id int(10) not null,
forum_id int(10) not null,
primary key(moderator_id)
);";
$results = ExeSQL($SQL);
/* Create the 'administrators' table */
$SQL = "create table " . $table_prefix . "administrators
(
admin_id int(10) not null auto_increment,
user_id int(10) not null,
primary key(admin_id)
);";
$results = ExeSQL($SQL);
/* Create the 'schemes' table */
$SQL = "create table " . $table_prefix . "schemes
(
scheme_id int(10) not null auto_increment,
scheme_name varchar(64) not null,
scheme_desc varchar(255) not null default 'No description provided.',
background_color varchar(7) not null default '#FFFFFF',
table_border_color varchar(7) not null default '#000000',
table_border_size int(1) not null default '1',
header_background varchar(7) not null default '#FFFFFF',
menu_background varchar(7) not null default '#EEEEEE',
text_color varchar(7) not null default '#000000',
text_font varchar(64) not null default 'Verdana',
text_small int(2) not null default '10',
text_regular int(2) not null default '12',
link_color varchar(7) not null default '#000000',
table_header_background varchar(7) not null default '#000000',
table_header_text_color varchar(7) not null default '#FFFFFF',
table_color_1 varchar(7) not null default '#EEEEEE',
table_color_2 varchar(7) not null default '#CCCCCC',
error_message varchar(7) not null default '#FF0000',
active_scheme varchar(1) not null default '0',
primary key(scheme_id)
);";
$results = ExeSQL($SQL);
/* Create the 'properties' table */
$SQL = "create table " . $table_prefix . "properties
(
board_name varchar(64) not null default 'Forums',
title_image varchar(128) not null default './images/title.png'
);";
$results = ExeSQL($SQL);
/* Insert the default schemes into the database */
$SQL = "INSERT INTO " . $table_prefix . "schemes VALUES (1,'default','Default scheme for b^2. This scheme was the original color scheme used when developing the software.','#FFFFFF','#000000',1,'#FFFFFF','#EEEEEE','#000000','Verdana',10,12,'#000000','#000000','#FFFFFF','#EEEEEE','#CCCCCC','#FF0000','1'),(2,'freshmeat','This scheme is a rip off of the baby blue color scheme that Freshmeat.net uses on their site.','#FFFFFF','#6F6F6F',1,'#FFFFFF','#DDDDDD','#000000','Verdana, Tahoma, Arial, Helvetica',12,14,'#3366CC','#BBDDFF','#000000','#FFFFFF','#EEEEEE','#FF0000','');";
$results = ExeSQL($SQL);
/* Insert the inital forum into the table */
$SQL = "INSERT INTO " . $table_prefix . "forums (forum_order, forum_name, forum_desc) VALUES ('0', '$forum_name', '$forum_desc');";
$results = ExeSQL($SQL);
/* If no title image was specified, then use the default */
if ($title_image == "")
$title_image = "./images/title.png";
/* Insert the properties into the table */
$SQL = "INSERT INTO " . $table_prefix . "properties (board_name, title_image) VALUES ('$board_name', '$title_image');";
$results = ExeSQL($SQL);
/* Crypt the admin password to a random salt */
$admin_pass = crypt($admin_pass);
/* Insert the administrator user account into the table */
$SQL = "INSERT INTO " . $table_prefix . "users (user_name, user_pass, user_email) VALUES ('$admin_user', '$admin_pass', '$admin_email');";
$results = ExeSQL($SQL);
/* Insert the user as an administrator */
$SQL = "INSERT INTO " . $table_prefix . "administrators (user_id) VALUES ('1');";
$results = ExeSQL($SQL);
/* If the file exists, then rename it */
if (file_exists("config.php"))
@rename ("config.php", "config.php.bak");
/* Open the file to write to it, display any problems */
if (!$fp = @fopen("config.php", "w"))
ShowConfigProblem();
else
{
/* If we can't write to it, then display an error */
if (!fwrite($fp, $config_file))
ShowConfigProblem();
else
fclose($fp);
/* Yay b^2 installed correctly!! */
echo "<CENTER>b^2 " . VERSION . " has successfully been installed, <A href=\"./\">click here</A> to view your new board.</CENTER>\n";
}
ShowFooter();
}
/* It's probably a good time to close the database connection */
mysql_close(CONNECTION);
break;
/* This is where we output the config.php if the user was wack and didn't chmod 777 the directory */
case 3:
header("Content-Type: text/x-delimtext; name=\"config.php\"");
header("Content-disposition: attachment; filename=config.php");
echo $config_file;
exit();
break;
}
/*
* This is the HTML header for the page ...
*/
function
ShowHeader()
{
echo "<HTML>\n"
. " <HEAD>\n"
. " <TITLE>" . INSTALL_TITLE . "</TITLE>\n"
. " <STYLE>\n"
. " body, td, input\n"
. " {\n"
. " font-family: Verdana;\n"
. " font-size: 10pt;\n"
. " }\n"
. " hr\n"
. " {\n"
. " color: #000000;\n"
. " height: 1;\n"
. " }\n"
. " </STYLE>\n"
. " </HEAD>\n"
. " <BODY>\n"
. " <CENTER><H3><U>" . INSTALL_TITLE . "</U></H3></CENTER>\n";
}
/*
* ... and this is the HTML footer
*/
function
ShowFooter()
{
echo " </BODY>\n"
. "</HTML>";
}
/*
* Show any problems with the config file.
*/
function
ShowConfigProblem()
{
echo " Installation is complete, well almost ;) Seems that the installation script wasn't able to write the 'config.php' file to your system (you didn't remember to chmod 777 the directory, did you?) No big deal, If you click the button below, you'll be able to download the file to your local system. From there, you'll want to upload that bad boy to your server, and place it in the b^2 directory. You will need to upload the 'config.php' file to the directory that b^2 was placed in."
. " <FORM method=\"POST\" name=\"installer\">\n"
. " <INPUT type=\"hidden\" name=\"db_user\" value=\"" . DB_USER . "\">\n"
. " <INPUT type=\"hidden\" name=\"db_pass\" value=\"" . DB_PASS . "\">\n"
. " <INPUT type=\"hidden\" name=\"db_name\" value=\"" . DB_NAME . "\">\n"
. " <INPUT type=\"hidden\" name=\"db_host\" value=\"" . DB_HOST . "\">\n"
. " <INPUT type=\"hidden\" name=\"table_prefix\" value=\"" . TABLE_PREFIX . "\">\n"
. " <INPUT type=\"hidden\" name=\"step\" value=\"3\">\n"
. " <CENTER><INPUT type=\"submit\" name=\"what\" value=\"Download 'config.php' Now!\"></CENTER>\n"
. " </FORM>\n";
}
?>