<?
/*
The Next BBS - Forums Software
Copyright (C) 2004 Chris F. Ravenscroft
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; either version 2 of the License, or (at your option) any later version.
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; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Questions? We can be reached at http://forums.sf.net
*/
require_once "wizard.php";
class SelectOp extends Wizard
{
function init()
{
$this->setPrev('splash');
$this->setNext('selector'); // Self by default: will be changed dynamically down the road...
$this->setTitle('Select an Operation');
$this->setDefault('wiz->action', 'installmain');
}
function action()
{
$ne = $this->getVar('next');
if($ne!=null)
{
$wa = $this->getVar('wiz_action');
if(!$wa || $wa=='')
{
$this->wizard->pagename = 'selector'; // Not going anywhere. Select something first!
}
else
{
$this->wizard->pagename = $wa;
}
}
}
function setPage()
{
$blockBody = <<<EOB
Please select what you wish to do today:<br />
Do you wish to install a new board from scratch? If you do so over an existing board, old data will be lost.<br />
Or do you wish to upgrade an existing board with this version? All data should be preserved.
EOB;
$expl = $this->getBlockCode($blockBody);
$formBody = <<<EOB
<input type="radio" [*wiz_action.installmain*] name="wiz_action" value="installmain">
New Install
<br />
<input type="radio" [*wiz_action.upgrademain*] name="wiz_action" value="upgrademain">
Upgrade Existing Install
EOB;
$this->page = $expl . $formBody;
}
}
class InstallMain extends Wizard
{
function init()
{
$this->setPrev('selector');
$this->setNext('installlayer');
$this->setTitle('New Install Operation');
}
function setPage()
{
$blockBody = <<<EOB
Select which database engine you are going to use.<br />
The database engine must be installed and running.<br />
Note: at this stage, MySQL is highly recommended since it was thoroughly tested.
EOB;
$expl = $this->getBlockCode($blockBody);
$formBody = <<<EOB
<select name='wiz_dbengine'>
<option [*wiz_dbengine.mysql*] value='mysql'> MySQL </option>
<option [*wiz_dbengine.postgres*] value='postgres'> Postgres </option>
<option [*wiz_dbengine.postgres64*] value='postgres64'> Postgres64 </option>
<option [*wiz_dbengine.db2*] value='db2'> IBM db2 </option>
<option [*wiz_dbengine.mssql*] value='mssql'> Microsoft SQL Server </option>
<option [*wiz_dbengine.oci8*] value='oci8'> Oracle 8/9 </option>
<option [*wiz_dbengine.vfp*] value='vfp'> Visual FoxPro </option>
<option [*wiz_dbengine.odbc*] value='odbc'> ODBC-Enabled </option>
<option [*wiz_dbengine.access*] value='access'> Microsoft Access </option>
<option [*wiz_dbengine.ado*] value='ado'> ADO-Compatible </option>
<option [*wiz_dbengine.ibase*] value='ibase'> Interbase </option>
<option [*wiz_dbengine.sqlite*] value='sqlite'> Sqlite </option>
</select>
EOB;
$this->page = $expl . $formBody;
}
}
class InstallLayer extends Wizard
{
function init()
{
$this->setPrev('installmain');
$this->setNext('installdb');
$this->setTitle('Database Abstraction Layer');
}
function setPage()
{
$blockBody = <<<EOB
Pick an abstraction layer.<br />
Note: AdoDb is installed automatically and provides better flexibility.
EOB;
$expl = $this->getBlockCode($blockBody);
$formBody = <<<EOB
<select name='wiz_dblayer'>
<option [*wiz_dblayer.adodb*] value='adodb'> AdoDb </option>
<option [*wiz_dblayer.peardb*] value='peardb'> Pear::DB </option>
</select>
EOB;
$this->page = $expl . $formBody;
}
}
class InstallDb extends Wizard
{
function init()
{
$this->setPrev('installlayer');
$this->setNext('installcheckdb');
$this->setTitle('Check Database Settings');
$this->setDefaults(array('wiz_dbhost'=>'localhost', 'wiz_dbprefix'=>'bb_'));
}
function setPage()
{
$blockBody = <<<EOB
Enter the name of an existing database as well as the name and password<br />
of a user who has create privileges on this database.<br />
The prefix will be used to prefix all your table's name.
EOB;
$expl = $this->getBlockCode($blockBody);
$formBody = <<<EOB
<table border="0">
<tr><td>
Database Name:
</td><td>
<input type='text' name='wiz_dbname' value='[*wiz_dbname*]'>
</tr><tr><td>
Database Host:
</td><td>
<input type='text' name='wiz_dbhost' value='[*wiz_dbhost*]'>
</tr><tr><td>
Tables Prefix:
</td><td>
<input type='text' name='wiz_dbprefix' value='[*wiz_dbprefix*]'>
</tr><tr><td>
Database User:
</td><td>
<input type='text' name='wiz_dbuser' value='[*wiz_dbuser*]'>
</tr><tr><td>
Database Password:
</td><td>
<input type='text' name='wiz_dbpassword' value='[*wiz_dbpassword*]'>
</td></td></table>
EOB;
$this->page = $expl . $formBody;
}
}
class InstallCheckDb extends Wizard
{
function init()
{
$this->setPrev('installdb');
$this->setNext('installdbdata');
$this->setTitle('Check Database Settings');
}
function action()
{
$this->displayProgress();
}
function setPage()
{
$diags = $this->checkdb(
$this->getVar('wiz_dblayer'),
$this->getVar('wiz_dbengine'),
$this->getVar('wiz_dbhost'),
$this->getVar('wiz_dbname'),
$this->getVar('wiz_dbuser'),
$this->getVar('wiz_dbpassword'));
$res_connect = $diags['Connect'] == false ? '<font color="red">Fail</font>' : '<font color="green">Pass</font>';
$res_create = $diags['Create'] == false ? '<font color="red">Fail</font>' : '<font color="green">Pass</font>';
$res_insert = $diags['Insert'] == false ? '<font color="red">Fail</font>' : '<font color="green">Pass</font>';
$res_update = $diags['Update'] == false ? '<font color="red">Fail</font>' : '<font color="green">Pass</font>';
$res_select = $diags['Select'] == false ? '<font color="red">Fail</font>' : '<font color="green">Pass</font>';
$res_delete = $diags['Delete'] == false ? '<font color="red">Fail</font>' : '<font color="green">Pass</font>';
$res_drop = $diags['Drop'] == false ? '<font color="red">Fail</font>' : '<font color="green">Pass</font>';
$bSuccess = true;
if (
$diags['Connect'] == false ||
$diags['Create'] == false ||
$diags['Insert'] == false ||
$diags['Update'] == false ||
$diags['Select'] == false ||
$diags['Delete'] == false ||
$diags['Drop'] == false
)
$bSuccess = false;
$blockBody = "Checking various database settings and user's privileges.<br />";
if($bSuccess)
{
$blockBody .= '<font color="green">Success!</font> - Your database is properly configured.<br />Click on [Next] to import new data in the database: this may take a while, please be patient.';
}
else
{
$blockBody .= '<font color="red">Failure!</font> - You need to change your settings before proceeding any further.';
$this->setNext(null);
}
$expl = $this->getBlockCode($blockBody);
$formBody = <<<EOB
<div align="center">
<table border="0" cellpadding="1" cellspacing="2" class="tableborder2">
<tr><td align="left">
Connect
</td><td align="left">
{$res_connect}
</tr><tr><td align="right">
Create
</td><td align="left">
{$res_create}
</tr><tr><td align="right">
Insert
</td><td align="left">
{$res_insert}
</tr><tr><td align="right">
Update
</td><td align="left">
{$res_update}
</tr><tr><td align="right">
Select
</td><td align="left">
{$res_select}
</tr><tr><td align="right">
Delete
</td><td align="left">
{$res_delete}
</tr><tr><td align="right">
Drop
</td><td align="left">
{$res_drop}
</td></tr></table>
</div>
EOB;
$this->page = $expl . $formBody;
}
}
class InstallDbData extends Wizard
{
function init()
{
$this->setPrev('installdb');
$this->setNext('installcheckfs');
$this->setTitle('Install Database Data');
}
function setPage()
{
// Admin password
$password = $this->getNewPassword();
$this->setUserVariable('password', $password);
$subs = array('[your_password]' => "PASSWORD('".$password."')");
$diag = $this->importdb(
$this->getVar('wiz_dblayer'),
$this->getVar('wiz_dbengine'),
$this->getVar('wiz_dbhost'),
$this->getVar('wiz_dbname'),
$this->getVar('wiz_dbuser'),
$this->getVar('wiz_dbpassword'),
'safedump.sql',
'chris_',
$this->getVar('wiz_dbprefix'),
$subs);
$blockBody = "Inserting all required data in the database.<br />";
if($diag=='OK')
{
$blockBody .= '<font color="green">Success!</font> - Your database is now ready.';
}
else
{
$blockBody .= '<font color="red">Failure!</font> - Reported Error:<br /><i>'.$diag.'</i>';
$this->setNext(null);
}
$expl = $this->getBlockCode($blockBody);
$formBody = <<<EOB
<div align="center">
EOB;
$this->page = $expl . $formBody;
}
}
class InstallCheckFs extends Wizard
{
function init()
{
$this->setPrev('installdb');
$this->setNext('installfsdata');
$this->setTitle('Check Filesystem Settings');
}
function setPage()
{
$diags = array(
'mkdirtpl' => false,
'chmodtpl' => false,
'mkdirsrv' => false,
'chmodsrv' => false,
'writefs' => false,
'chmodfs' => false,
);
$bogusdir = 'servers/1/templates/bogusdir';
$diags['mkdirtpl'] = $this->mkdir($bogusdir);
if($diags['mkdirtpl'])
{
$diags['chmodtpl'] = $this->chmod($bogusdir, 0755);
$this->rmdir($bogusdir);
}
$bogusdir = 'servers/1/bogusdir';
$diags['mkdirsrv'] = $this->mkdir($bogusdir);
if($diags['mkdirsrv'])
{
$diags['chmodsrv'] = $this->chmod($bogusdir, 0755);
$this->rmdir($bogusdir);
}
$bogusfile = 'bogusfile';
$diags['writefs'] = $this->writefile($bogusfile, 'Test');
if($diags['writefs'])
{
$diags['chmodfs'] = $this->chmod($bogusfile, 0755);
$this->deletefile($bogusfile);
}
$res_mkdirtpl = $diags['mkdirtpl'] == false ? '<font color="red">Fail</font>' : '<font color="green">Pass</font>';
$res_chmodtpl = $diags['chmodtpl'] == false ? '<font color="red">Fail</font>' : '<font color="green">Pass</font>';
$res_mkdirsrv = $diags['mkdirsrv'] == false ? '<font color="red">Fail</font>' : '<font color="green">Pass</font>';
$res_chmodsrv = $diags['chmodsrv'] == false ? '<font color="red">Fail</font>' : '<font color="green">Pass</font>';
$res_writefs = $diags['writefs'] == false ? '<font color="red">Fail</font>' : '<font color="green">Pass</font>';
$res_chmodfs = $diags['chmodfs'] == false ? '<font color="red">Fail</font>' : '<font color="green">Pass</font>';
$bSuccess = true;
if (
$diags['mkdirtpl'] == false ||
$diags['chmodtpl'] == false ||
$diags['mkdirsrv'] == false ||
$diags['chmodsrv'] == false ||
$diags['writefs'] == false ||
$diags['chmodfs'] == false
)
$bSuccess = false;
$blockBody = "Checking various filesystem settings and user's privileges.<br />";
if($bSuccess)
{
$blockBody .= '<font color="green">Success!</font> - Your filesystem is properly configured.<br />Click on [Next] to create new directories and modify access rights.';
}
else
{
$adds = '';
if($diags['mkdirtpl']==false)
$adds .= '[ servers/1/templates/ ]<br />';
if($diags['mkdirsrv']==false)
$adds .= '[ servers/1/ ]<br />';
if($diags['writefs']==false)
$adds .= '[ ./ ]<br />';
$blockBody .= '<font color="red">Failure!</font> - You need to change access rights on<br />'.$adds.'before proceeding any further.';
$this->setNextCaption('Retry');
$this->setNext('installcheckfs');
}
$expl = $this->getBlockCode($blockBody);
$formBody = <<<EOB
<div align="center">
<table border="0" cellpadding="1" cellspacing="2" class="tableborder2">
<tr><td align="left">
Create subdirectory of servers/1/templates/
</td><td align="left">
{$res_mkdirtpl}
</tr><tr><td align="right">
Change mode of subdirectory
</td><td align="left">
{$res_chmodtpl}
</tr><tr><td align="right">
Create subdirectory of servers/1/
</td><td align="left">
{$res_mkdirsrv}
</tr><tr><td align="right">
Change mode of subdirectory
</td><td align="left">
{$res_chmodsrv}
</tr><tr><td align="right">
Create a file at the install's root level (.)
</td><td align="left">
{$res_writefs}
</tr><tr><td align="right">
Change mode of file
</td><td align="left">
{$res_chmodfs}
</td></tr></table>
</div>
EOB;
$this->page = $expl . $formBody;
}
}
class InstallFsData extends Wizard
{
function init()
{
$this->setPrev('installcheckfs');
$this->setNext('installfinalmain');
$this->setTitle('Install Files');
}
function setPage()
{
$diags = array(
'1_c' => false,
'2_c' => false,
'3_c' => false,
'avatars' => false,
'emoticons' => false,
'attachments' => false,
'uploads' => false,
'config' => false,
);
$d = 'servers/1/templates/1_c'; $diags['1_c'] = $this->mkdir($d); if($diags['1_c']) $this->chmod($d, 0777);
$d = 'servers/1/templates/2_c'; $diags['2_c'] = $this->mkdir($d); if($diags['2_c']) $this->chmod($d, 0777);
$d = 'servers/1/templates/3_c'; $diags['3_c'] = $this->mkdir($d); if($diags['3_c']) $this->chmod($d, 0777);
$d = 'servers/1/avatars'; $diags['avatars'] = $this->mkdir($d); if($diags['avatars']) $this->chmod($d, 0777);
$d = 'servers/1/emoticons'; $diags['emoticons'] = $this->mkdir($d); if($diags['emoticons']) $this->chmod($d, 0777);
$d = 'servers/1/attachments'; $diags['attachments'] = $this->mkdir($d); if($diags['attachments']) $this->chmod($d, 0777);
$d = 'servers/1/uploads'; $diags['uploads'] = $this->mkdir($d); if($diags['uploads']) $this->chmod($d, 0777);
// Setup bootstrap configuration file
$contents = $this->readFile("config-dist.php");
if($contents)
{
$contents = str_replace("{db_layer}", $this->getVar('wiz_dblayer'), $contents);
$contents = str_replace("{db_engine}", $this->getVar('wiz_dbengine'), $contents);
$contents = str_replace("{db_hostname}", $this->getVar('wiz_dbhost'), $contents);
$contents = str_replace("{db_name}", $this->getVar('wiz_dbname'), $contents);
$contents = str_replace("{db_user}", $this->getVar('wiz_dbuser'), $contents);
$contents = str_replace("{db_pass}", $this->getVar('wiz_dbpassword'), $contents);
$contents = str_replace("{db_prefix}", $this->getVar('wiz_dbprefix'), $contents);
if($this->writeFile("config.php", $contents))
{
$diags['config'] = true;
}
}
$res_1_c = $diags['1_c'] == false ? '<font color="red">Fail</font>' : '<font color="green">OK</font>';
$res_2_c = $diags['2_c'] == false ? '<font color="red">Fail</font>' : '<font color="green">OK</font>';
$res_3_c = $diags['3_c'] == false ? '<font color="red">Fail</font>' : '<font color="green">OK</font>';
$res_avatars = $diags['avatars'] == false ? '<font color="red">Fail</font>' : '<font color="green">OK</font>';
$res_emoticons = $diags['emoticons'] == false ? '<font color="red">Fail</font>' : '<font color="green">OK</font>';
$res_attachments = $diags['attachments'] == false ? '<font color="red">Fail</font>' : '<font color="green">OK</font>';
$res_uploads = $diags['uploads'] == false ? '<font color="red">Fail</font>' : '<font color="green">OK</font>';
$res_config = $diags['config'] == false ? '<font color="red">Fail</font>' : '<font color="green">OK</font>';
$bSuccess = true;
if (
$diags['1_c'] == false ||
$diags['2_c'] == false ||
$diags['3_c'] == false ||
$diags['avatars'] == false ||
$diags['emoticons'] == false ||
$diags['attachments'] == false ||
$diags['uploads'] == false ||
$diags['config'] == false
)
$bSuccess = false;
$blockBody = "Creating all required files and directories.<br />";
if($bSuccess)
{
$blockBody .= '<font color="green">Success!</font> - Your files were all installed.';
}
else
{
$blockBody .= '<font color="red">Failure!</font> - Please see report below.';
$this->setNext(null);
}
$expl = $this->getBlockCode($blockBody);
$formBody = <<<EOB
<div align="center">
<table border="0" cellpadding="1" cellspacing="2" class="tableborder2">
<tr><td align="left">
Create subdirectory servers/1/templates/1_c/
</td><td align="left">
{$res_1_c}
</tr><tr><td align="right">
Create subdirectory servers/1/templates/2_c/
</td><td align="left">
{$res_2_c}
</tr><tr><td align="right">
Create subdirectory servers/1/templates/3_c/
</td><td align="left">
{$res_3_c}
</tr><tr><td align="right">
Create subdirectory servers/1/avatars/
</td><td align="left">
{$res_avatars}
</tr><tr><td align="right">
Create subdirectory servers/1/emoticons/
</td><td align="left">
{$res_emoticons}
</tr><tr><td align="right">
Create subdirectory servers/1/attachments/
</td><td align="left">
{$res_attachments}
</tr><tr><td align="right">
Create subdirectory servers/1/uploads/
</td><td align="left">
{$res_uploads}
</tr><tr><td align="right">
Create configuration file: config.php
</td><td align="left">
{$res_config}
</td></tr></table>
</div>
EOB;
$this->page = $expl . $formBody;
}
}
class InstallFinalMain extends Wizard
{
function init()
{
$this->setCancel(null);
$this->setSubmit('index.php');
$this->setTitle('Install Complete');
}
function setPage()
{
$password = $this->getUserVariable('password');
$blockBody = <<<EOB
<div align='center'>
<i>Your message board is now ready: a default admin user, 'admin', was created. This user's password is <b>{$password}</b></i>
<br /><br />
Thank you for helping us beta-test this software!<br />
<br /><br />
<font color='red'><b>Security Warning: Do not forget to delete install.php!!
</b></font>
<br /><br />
<a href='index.php'>Visit your Board</a>
</div>
EOB;
$this->page = $this->getBlockCode($blockBody);
}
}
class UpgradeMain extends Wizard
{
function init()
{
$this->setPrev('selector');
$this->setTitle('Upgrade Card');
}
function setPage()
{
$blockBody = "Sorry, the upgrade feature is not ready yet.";
$this->page = $this->getBlockCode($blockBody);
}
}
// This is a legit script
$BOARD_FLOW = 1;
// Let's get this over with...
require_once "tidbit.php";
$wizard = new Wizard();
$wizard->setDimensions(640, 480);
$selectOp = new SelectOp('selector'); $wizard->addPage('selector', $selectOp);
$installMain = new InstallMain('installmain'); $wizard->addPage('installmain', $installMain);
$installlayer = new InstallLayer('installlayer'); $wizard->addPage('installlayer', $installlayer);
$installdb = new InstallDb('installdb'); $wizard->addPage('installdb', $installdb);
$installcheckdb = new InstallCheckDb('installcheckdb'); $wizard->addPage('installcheckdb', $installcheckdb);
$installdbdata = new InstallDbData('installdbdata'); $wizard->addPage('installdbdata', $installdbdata);
$installcheckfs = new InstallCheckFs('installcheckfs'); $wizard->addPage('installcheckfs', $installcheckfs);
$installfsdata = new InstallFsData('installfsdata'); $wizard->addPage('installfsdata', $installfsdata);
$installfinalmain = new InstallFinalMain('installfinalmain'); $wizard->addPage('installfinalmain', $installfinalmain);
$upgradeMain = new upgradeMain('upgrademain'); $wizard->addPage('upgrademain', $upgradeMain);
$installfinalmain = new InstallFinalMain('installfinalmain'); $wizard->addPage('installfinalmain', $installfinalmain);
$wizard->display();
?>
|