Script written by Matthew Mecham
| > Date started: 30th March 2002
| > Update started: 17th October 2002
|
+--------------------------------------------------------------------------
*/
error_reporting (E_ERROR | E_WARNING | E_PARSE);
set_magic_quotes_runtime(0);
//+---------------------------------------
// ENTER YOUR PATH TO THE DIRECTORY THIS SCRIPT
// IS IN.
//
// Tips:
//
// If you are using Windows and Apache, do not
// use backslashes, use normal forward slashes.
// You may need to remove the drive letter also
// Example: C:\apache\htdocs\ibforums\ will need
// to be: /apache/htdocs/ibforums/
//
// If you are using Windows and IIS, then you will
// need to enter double backslashes.
//
// In all cases, please enter a trailing slash (or
// trailing backslashes...)
//+---------------------------------------
$root = "./";
//+---------------------------------------
$template = new template;
$std = new installer;
$VARS = $std->parse_incoming();
//+---------------------------------------
// What are we doing then? Eh? I'm talking to you!
//+---------------------------------------
if ( file_exists($root.'install.lock') )
{
install_error("This installer is locked!
Please (via FTP) remove the 'install.lock' file in this directory");
exit();
}
switch($VARS['a'])
{
case '1':
do_setup_form();
break;
case '2':
do_install();
break;
case 'templates':
do_templates();
break;
case '3':
do_finish();
break;
default:
do_intro();
break;
}
function do_finish()
{
global $std, $template, $root, $VARS, $SQL;
// Attempt to lock the install..
if ($FH = @fopen( $root.'install.lock', 'w' ) )
{
@fwrite( $FH, 'bleh', 4 );
@fclose($FH);
@chmod( $root.'install.lock', 0666 );
$template->print_top('Success!');
$msg="Although the installer is now locked (to re-install, remove the file 'install.lock'), for added security, please remove the sm_install.php program before continuing.
CLICK HERE TO LOG IN!";
}
else
{
$template->print_top('Success!');
$msg = "PLEASE REMOVE THE INSTALLER ('sm_install.php') BEFORE CONTINUING!
Failure to do so will enable ANYONE to delete your board at any time!
CLICK HERE TO LOG IN!";
}
$template->contents .= "
Success
The installation is now complete!
$msg
";
$template->output();
}
//+---------------------------------------
// Install the template files, woohoo and stuff
//+---------------------------------------
function do_templates()
{
global $std, $template, $root, $VARS, $HTTP_POST_VARS;
//-----------------------------------
// IMPORT $INFO!
//-----------------------------------
if ($root == './')
{
$root = str_replace( '\\', '/', getcwd() ) . '/';
}
$require = $root."conf_global.php";
if ( ! file_exists($require) )
{
install_error("Could not locate '$require'. You may need to enter a value for the root path in this installer script, to do this, simply open up this script in a text editor and enter a value in \$root - remember to add a trailing slash. NT users will need to use double backslashes");
}
include($require);
//-----------------------------------
// Attempt a DB connection..
//-----------------------------------
if ( ! $connect_id = mysql_connect( $INFO['sql_host'],$INFO['sql_user'],$INFO['sql_pass'] ) )
{
install_error("Could not create a mySQL connection, please check that the file 'conf_global.php' exists in the same directory as this file and that the installer has updated the file properly.");
}
if ( ! mysql_select_db($INFO['sql_database'], $connect_id) )
{
install_error("mySQL could not locate a database called '{$VARS['sql_database']}'. Please contact our technical support if a re-install does not solve this problem");
}
//-----------------------------------
// Lets open the style file
//-----------------------------------
$style_file = $root.'install_templates.txt';
if ( ! file_exists($style_file) )
{
install_error("Could not locate '$style_file'.
Check to ensure that this file exists in the same location as this script.
You may need to enter a value for the root path in this installer script, to do this, simply open up this script in a text editor and enter a value in \$root - remember to add a trailing slash. NT users will need to use double backslashes");
}
if ( $fh = fopen( $style_file, 'r' ) )
{
$data = fread($fh, filesize($style_file) );
fclose($fh);
}
else
{
install_error("Could open '$style_file'");
}
if (strlen($data) < 100)
{
install_error("Err 1:'$style_file' is incomplete, please re-upload a fresh copy over the existing copy on the server'");
}
// Chop up the data file.
$template_rows = explode( "||~&~||", $data );
$crows = count($template_rows); //we're counting crows :o
if ( $crows < 100 )
{
install_error("Err2: (Found $crows rows) '$style_file' is incomplete, please re-upload a fresh copy over the existing copy on the server'");
}
//-----------------------------------
// Lets populate the database!
//-----------------------------------
foreach( $template_rows as $q )
{
$q = trim($q);
if (strlen($q) < 5)
{
continue;
}
$query = "INSERT INTO ".$INFO['sql_tbl_prefix']."skin_templates (set_id, group_name, section_content, func_name, func_data, updated, can_remove) VALUES $q";
if ( ! mysql_query($query, $connect_id) )
{
install_error("mySQL Error: ".mysql_error());
}
}
// ARE WE DONE? REALLY? COOL!!
$template->print_top('Success!');
$template->contents .= "
Success
Template files installed!
The installation process is now complete.
Click the link below to clean up the installer and related files
CLICK HERE TO FINISH
";
$template->output();
}
//+---------------------------------------
function do_install()
{
global $std, $template, $root, $VARS, $HTTP_POST_VARS;
// Ok, lets check for blankies...
$NEW_INFO = array();
$need = array('board_url','sql_host','sql_database','sql_user','adminname','adminpassword','adminpassword2','email');
//-----------------------------------
foreach($need as $greed)
{
if ($VARS[ $greed ] == "")
{
install_error("You must complete all of the form with the sole exception of 'SQL Table prefix'");
}
}
//-----------------------------------
$VARS['board_url'] = preg_replace( "#/$#", "", $VARS['board_url'] );
if ($VARS['sql_tbl_prefix'] == "")
{
$VARS['sql_tbl_prefix'] = 'ibf_';
}
//-----------------------------------
// Did the admin passy and passy2 match?
//-----------------------------------
if ($VARS['adminpassword2'] != $VARS['adminpassword'])
{
install_error("Your passwords did not match");
}
/*if ( ! preg_match( "!^http://!", $VARS['board_url'] ) )
{
install_error("The board URL must start with 'http://'");
}*/
//-----------------------------------
// IMPORT $INFO!
//-----------------------------------
if ($root == './')
{
$root = str_replace( '\\', '/', getcwd() ) . '/';
}
$require = $root."conf_global.php";
if ( ! file_exists($require) )
{
install_error("Could not locate '$require'. You may need to enter a value for the root path in this installer script, to do this, simply open up this script in a text editor and enter a value in \$root - remember to add a trailing slash. NT users will need to use double backslashes");
}
//@chmod( "conf_global.php", 0666 );
include($require);
//echo("here");
//exit();
if ( count($INFO) < 1 )
{
install_error("Possible corruption in 'conf_global.php' ({$VARS['base_dir']}conf_global.php), please re-upload in ASCII format");
}
//-----------------------------------
// Attempt a DB connection..
//-----------------------------------
if ( ! $connect_id = mysql_connect( $VARS['sql_host'],$HTTP_POST_VARS['sql_user'],$HTTP_POST_VARS['sql_pass'] ) )
{
install_error("Could not create a mySQL connection, please check the SQL values entered");
}
if ( ! mysql_select_db($VARS['sql_database'], $connect_id) )
{
install_error("mySQL could not locate a database called '{$VARS['sql_database']}' please check the value entered for this");
}
//-----------------------------------
// Attempt to write the config file.
//-----------------------------------
$new = array( 'base_dir' => $root,
'board_url' => $VARS['board_url'],
'sql_host' => $VARS['sql_host'],
'sql_database' => $VARS['sql_database'],
'sql_user' => $HTTP_POST_VARS['sql_user'],
'sql_pass' => $HTTP_POST_VARS['sql_pass'],
'sql_tbl_prefix' => $VARS['sql_tbl_prefix'],
'html_dir' => $root."html/",
'html_url' => $VARS['board_url']."/html",
'upload_dir' => $root."uploads",
'upload_url' => $VARS['board_url']."/uploads",
'email_in' => $VARS['email'],
'email_out' => $VARS['email'],
'ban_names' => "",
'ban_email' => "",
'ban_ip' => "",
'force_login' => 0,
'load_limit' => "",
'board_start' => time(),
'installed' => 1,
'guests_ava' => 1,
'guests_img' => 1,
'guests_sig' => 1,
'print_headers' => 0,
'guest_name_pre' => "Guest_",
);
foreach( $new as $k => $v )
{
// Update the old...
$v = preg_replace( "/'/", "\\'" , $v );
$v = preg_replace( "/\r/", "" , $v );
$INFO[ $k ] = $v;
}
$file_string = " $v )
{
if ($k == 'skin' or $k == 'languages')
{
continue;
}
$file_string .= '$INFO['."'".$k."'".']'."\t\t\t=\t'".$v."';\n";
}
$file_string .= "\n".'?'.'>'; // Question mark + greater than together break syntax hi-lighting in BBEdit 6 :p
if ( $fh = fopen( $require, 'w' ) )
{
fputs($fh, $file_string, strlen($file_string) );
fclose($fh);
}
else
{
install_error("Could not write to 'conf_global.php'");
}
//-----------------------------------
// What MySQL version are we running?
//-----------------------------------
$a = mysql_query("SELECT VERSION() AS version", $connect_id);
if ( ! $row = mysql_fetch_array($a) )
{
$b = mysql_query("SHOW VARIABLES LIKE 'version'", $connect_id);
$row = mysql_fetch_array($b);
}
$mysql_version = 32100;
$no_array = explode( '.', preg_replace( "/^(.+?)[-_]?/", "\\1", $row['version']) );
$one = (!isset($no_array) || !isset($no_array[0])) ? 3 : $no_array[0];
$two = (!isset($no_array[1])) ? 21 : $no_array[1];
$three = (!isset($no_array[2])) ? 0 : $no_array[2];
$mysql_version = (int)sprintf('%d%02d%02d', $one, $two, intval($three));
//-----------------------------------
// Lets populate the database!
//-----------------------------------
$SQL = get_sql();
foreach( $SQL as $q )
{
if ($VARS['sql_tbl_prefix'] != "ibf_")
{
$q = preg_replace("/ibf_(\S+?)([\s\.,]|$)/", $VARS['sql_tbl_prefix']."\\1\\2", $q);
}
$q = str_replace( "<%time%>", time(), $q );
if ( preg_match("/CREATE TABLE (\S+) \(/", $q, $match) )
{
if ($match[1])
{
$the_query = "DROP TABLE if exists ".$match[1];
if (! mysql_query($the_query, $connect_id) )
{
install_error("mySQL Error: ".mysql_error());
}
}
}
if ( $mysql_version < 32323 )
{
$q = str_replace( "KEY forum_id (forum_id,approved,pinned),FULLTEXT KEY title (title)", 'KEY forum_id (forum_id,approved,pinned)', $q );
$q = str_replace( "KEY forum_id (forum_id,post_date),FULLTEXT KEY post (post)" , 'KEY forum_id (forum_id,post_date)' , $q );
}
if ( ! mysql_query($q, $connect_id) )
{
install_error("mySQL Error: ".mysql_error()."
Query:".$q);
}
}
// Insert the admin...
$passy = md5($VARS['adminpassword']);
$time = time();
$query = "INSERT INTO ".$VARS['sql_tbl_prefix']."members (id, name, mgroup, password, email, joined, ip_address, posts, title, last_visit, last_activity) ".
"VALUES(1, '{$VARS['adminname']}', 4, '$passy', '{$VARS['email']}', '$time', '127.0.0.1', '0', 'Administrator', '$time', '$time')";
if ( ! mysql_query($query, $connect_id) )
{
install_error("mySQL Error: ".mysql_error());
}
// ARE WE DONE? REALLY? COOL!!
$template->print_top('Success!');
$template->contents .= "
Success
Your board has now been installed!
The installation process is almost complete.
The next and final step will install the template files into your database
CLICK HERE TO CONTINUE
";
$template->output();
}
function do_setup_form()
{
global $std, $template, $root, $HTTP_SERVER_VARS;
$template->print_top('Set Up form');
//--------------------------------------------------
$this_url = str_replace( "/sm_install.php", "", $HTTP_SERVER_VARS['HTTP_REFERER']);
if ( ! $this_url )
{
$this_url = substr($HTTP_SERVER_VARS['SCRIPT_NAME'],0, -15);
if ($this_url == '')
{
$this_url == '/';
}
$this_url = 'http://'.$HTTP_SERVER_VARS['SERVER_NAME'].$this_url;
}
//--------------------------------------------------
$template->contents .= "
";
$template->output();
}
//+---------------------------------------
function do_intro()
{
global $std, $template, $root;
$template->print_top('Welcome');
$template->contents .= "
|
Before we go any further, please ensure that all the files have been uploaded, and that the
file 'conf_global.php' has suitable permissions to allow this script to write to it ( 0666 should be sufficient ).
You will also need the following information that your webhost can provide:
- Your MySQL database name
- Your MySQL username
- Your MySQL password
- Your MySQL host address (usually localhost)
Once you have clicked on proceed, you will be taken to a form to enter information the installer needs to set up your board.
PLEASE NOTE: USING THIS INSTALLER WILL DELETE ANY CURRENT INVISION POWER BOARD DATABASE IF YOU ARE USING THE SAME TABLE PREFIX
";
// Check to make sure that the config file is there and it's got suitable permissions to write to:
$file = $root."conf_global.php";
$style_file = $root."install_templates.txt";
$warnings = array();
if ( ! file_exists($style_file) )
{
$warnings[] = "Cannot locate the file 'install_templates.txt'. This should be uploaded into the same directory as this script!";
}
if ( ! file_exists($file) )
{
$warnings[] = "Cannot locate the file 'conf_global.php'. This should be uploaded into the same directory as this script!";
}
if ( ! is_writeable($file) )
{
$warnings[] = "Cannot write to 'conf_global.php'. Please adjust the permissions to allow this script to write to the file. if in doubt, CHMOD via FTP to 0777";
}
$phpversion = phpversion();
if ($phpversion < '4.0.0') {
$warnings[] = "You cannot install Invision Power Board. Invision Power Board requires PHP Version 4.0.0 or better.";
}
if ( count($warnings) > 0 )
{
$err_string = "- ".implode( "
- ", $warnings )."
";
$template->contents .= "
Warning!
The following errors must be rectified before continuing!
$err_string
";
}
else
{
$template->contents .= "
";
}
$template->contents .= " |
";
$template->output();
}
function install_error($msg="")
{
global $std, $template, $root;
$template->print_top('Warning!');
$template->contents .= "
Warning!
The following errors must be rectified before continuing!
Please go back and try again!
$msg
";
$template->output();
}
//+--------------------------------------------------------------------------
// CLASSES
//+--------------------------------------------------------------------------
class template
{
var $contents = "";
function output()
{
echo $this->contents;
echo "
Invision Power Board © 2003 Invision Power Services, Inc.