5
* @version $Id: index.php,v 1.71 2007/10/06 11:45:04 acydburn Exp $
6
* @copyright (c) 2005 phpBB Group
7
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
14
define('IN_PHPBB', true);
15
define('IN_INSTALL', true);
18
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './../';
19
$phpEx = substr(strrchr(__FILE__, '.'), 1);
21
// Report all errors, except notices
22
error_reporting(E_ALL ^ E_NOTICE);
24
// @todo Review this test and see if we can find out what it is which prevents PHP 4.2.x from even displaying the page with requirements on it
25
if (version_compare(PHP_VERSION, '4.3.3') < 0)
27
die('You are running an unsupported PHP version. Please upgrade to PHP 4.3.3 or higher before trying to install phpBB 3.0');
31
* Remove variables created by register_globals from the global scope
32
* Thanks to Matt Kavanagh
34
function deregister_globals()
47
'phpbb_root_path' => true
50
// Not only will array_merge and array_keys give a warning if
51
// a parameter is not an array, array_merge will actually fail.
52
// So we check if _SESSION has been initialised.
53
if (!isset($_SESSION) || !is_array($_SESSION))
58
// Merge all into one extremely huge array; unset this later
64
array_keys($_SESSION),
69
foreach ($input as $varname)
71
if (isset($not_unset[$varname]))
73
// Hacking attempt. No point in continuing unless it's a COOKIE
74
if ($varname !== 'GLOBALS' || isset($_GET['GLOBALS']) || isset($_POST['GLOBALS']) || isset($_SERVER['GLOBALS']) || isset($_SESSION['GLOBALS']) || isset($_ENV['GLOBALS']) || isset($_FILES['GLOBALS']))
81
while (isset($cookie['GLOBALS']))
83
foreach ($cookie['GLOBALS'] as $registered_var => $value)
85
if (!isset($not_unset[$registered_var]))
87
unset($GLOBALS[$registered_var]);
90
$cookie = &$cookie['GLOBALS'];
95
unset($GLOBALS[$varname]);
101
// If we are on PHP >= 6.0.0 we do not need some code
102
if (version_compare(PHP_VERSION, '6.0.0-dev', '>='))
107
define('STRIP', false);
111
set_magic_quotes_runtime(0);
113
// Be paranoid with passed vars
114
if (@ini_get('register_globals') == '1' || strtolower(@ini_get('register_globals')) == 'on')
116
deregister_globals();
119
define('STRIP', (get_magic_quotes_gpc()) ? true : false);
122
// Try to override some limits - maybe it helps some...
124
$mem_limit = @ini_get('memory_limit');
125
if (!empty($mem_limit))
127
$unit = strtolower(substr($mem_limit, -1, 1));
128
$mem_limit = (int) $mem_limit;
132
$mem_limit = floor($mem_limit / 1024);
134
else if ($unit == 'g')
138
else if (is_numeric($unit))
140
$mem_limit = floor((int) ($mem_limit . $unit) / 1048576);
142
$mem_limit = max(128, $mem_limit) . 'M';
148
@ini_set('memory_limit', $mem_limit);
150
// Include essential scripts
151
require($phpbb_root_path . 'includes/functions.' . $phpEx);
153
if (file_exists($phpbb_root_path . 'includes/functions_content.' . $phpEx))
155
require($phpbb_root_path . 'includes/functions_content.' . $phpEx);
158
include($phpbb_root_path . 'includes/auth.' . $phpEx);
159
include($phpbb_root_path . 'includes/session.' . $phpEx);
160
include($phpbb_root_path . 'includes/template.' . $phpEx);
161
include($phpbb_root_path . 'includes/acm/acm_file.' . $phpEx);
162
include($phpbb_root_path . 'includes/cache.' . $phpEx);
163
include($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
164
include($phpbb_root_path . 'includes/utf/utf_tools.' . $phpEx);
165
require($phpbb_root_path . 'includes/functions_install.' . $phpEx);
167
// Try and load an appropriate language if required
168
$language = basename(request_var('language', ''));
170
if (!empty($_SERVER['HTTP_ACCEPT_LANGUAGE']) && !$language)
172
$accept_lang_ary = explode(',', strtolower($_SERVER['HTTP_ACCEPT_LANGUAGE']));
173
foreach ($accept_lang_ary as $accept_lang)
175
// Set correct format ... guess full xx_yy form
176
$accept_lang = substr($accept_lang, 0, 2) . '_' . substr($accept_lang, 3, 2);
178
if (file_exists($phpbb_root_path . 'language/' . $accept_lang))
180
$language = $accept_lang;
185
// No match on xx_yy so try xx
186
$accept_lang = substr($accept_lang, 0, 2);
187
if (file_exists($phpbb_root_path . 'language/' . $accept_lang))
189
$language = $accept_lang;
196
// No appropriate language found ... so let's use the first one in the language
197
// dir, this may or may not be English
200
$dir = @opendir($phpbb_root_path . 'language');
204
die('Unable to access the language directory');
208
while (($file = readdir($dir)) !== false)
210
$path = $phpbb_root_path . 'language/' . $file;
212
if (!is_file($path) && !is_link($path) && file_exists($path . '/iso.txt'))
221
if (!file_exists($phpbb_root_path . 'language/' . $language))
223
die('No language found!');
226
// And finally, load the relevant language files
227
include($phpbb_root_path . 'language/' . $language . '/common.' . $phpEx);
228
include($phpbb_root_path . 'language/' . $language . '/acp/common.' . $phpEx);
229
include($phpbb_root_path . 'language/' . $language . '/acp/board.' . $phpEx);
230
include($phpbb_root_path . 'language/' . $language . '/install.' . $phpEx);
231
include($phpbb_root_path . 'language/' . $language . '/posting.' . $phpEx);
233
$mode = request_var('mode', 'overview');
234
$sub = request_var('sub', '');
236
// Set PHP error handler to ours
237
set_error_handler(defined('PHPBB_MSG_HANDLER') ? PHPBB_MSG_HANDLER : 'msg_handler');
241
$cache = new cache();
242
$template = new template();
244
// Add own hook handler, if present. :o
245
if (file_exists($phpbb_root_path . 'includes/hooks/index.' . $phpEx))
247
require($phpbb_root_path . 'includes/hooks/index.' . $phpEx);
248
$phpbb_hook = new phpbb_hook(array('exit_handler', 'phpbb_user_session_handler', 'append_sid', array('template', 'display')));
250
foreach ($cache->obtain_hooks() as $hook)
252
@include($phpbb_root_path . 'includes/hooks/' . $hook . '.' . $phpEx);
260
// Set some standard variables we want to force
262
'load_tplcompile' => '1'
265
$template->set_custom_template('../adm/style', 'admin');
266
$template->assign_var('T_TEMPLATE_PATH', '../adm/style');
268
// the acp template is never stored in the database
269
$user->theme['template_storedb'] = false;
271
$install = new module();
273
$install->create('install', "index.$phpEx", $mode, $sub);
277
$install->page_header();
278
$install->generate_navigation();
280
$template->set_filenames(array(
281
'body' => $install->get_tpl_name())
284
$install->page_footer();
292
var $type = 'install';
293
var $module_ary = array();
295
var $module_url = '';
301
* Private methods, should not be overwritten
303
function create($module_type, $module_url, $selected_mod = false, $selected_submod = false)
305
global $db, $config, $phpEx, $phpbb_root_path;
309
// Grab module information using Bart's "neat-o-module" system (tm)
310
$dir = @opendir('.');
314
$this->error('Unable to access the installation directory', __LINE__, __FILE__);
318
while (($file = readdir($dir)) !== false)
320
if (preg_match('#^install_(.*?)\.' . $phpEx . '$#', $file))
329
if (!sizeof($module))
331
$this->error('No installation modules found', __LINE__, __FILE__);
334
// Order to use and count further if modules get assigned to the same position or not having an order
335
$max_module_order = 1000;
337
foreach ($module as $row)
339
// Check any module pre-reqs
340
if ($row['module_reqs'] != '')
344
// Module order not specified or module already assigned at this position?
345
if (!isset($row['module_order']) || isset($this->module_ary[$row['module_order']]))
347
$row['module_order'] = $max_module_order;
351
$this->module_ary[$row['module_order']]['name'] = $row['module_title'];
352
$this->module_ary[$row['module_order']]['filename'] = $row['module_filename'];
353
$this->module_ary[$row['module_order']]['subs'] = $row['module_subs'];
354
$this->module_ary[$row['module_order']]['stages'] = $row['module_stages'];
356
if (strtolower($selected_mod) == strtolower($row['module_title']))
358
$this->id = (int) $row['module_order'];
359
$this->filename = (string) $row['module_filename'];
360
$this->module_url = (string) $module_url;
361
$this->mode = (string) $selected_mod;
362
// Check that the sub-mode specified is valid or set a default if not
363
if (is_array($row['module_subs']))
365
$this->sub = strtolower((in_array(strtoupper($selected_submod), $row['module_subs'])) ? $selected_submod : $row['module_subs'][0]);
367
else if (is_array($row['module_stages']))
369
$this->sub = strtolower((in_array(strtoupper($selected_submod), $row['module_stages'])) ? $selected_submod : $row['module_stages'][0]);
380
* Load and run the relevant module if applicable
382
function load($mode = false, $run = true)
384
global $phpbb_root_path, $phpEx;
393
$module = $this->filename;
394
if (!class_exists($module))
396
$this->error('Module "' . htmlspecialchars($module) . '" not accessible.', __LINE__, __FILE__);
398
$this->module = new $module($this);
400
if (method_exists($this->module, 'main'))
402
$this->module->main($this->mode, $this->sub);
408
* Output the standard page header
410
function page_header()
412
if (defined('HEADER_INC'))
417
define('HEADER_INC', true);
418
global $template, $lang, $stage, $phpbb_root_path;
420
$template->assign_vars(array(
421
'L_CHANGE' => $lang['CHANGE'],
422
'L_INSTALL_PANEL' => $lang['INSTALL_PANEL'],
423
'L_SELECT_LANG' => $lang['SELECT_LANG'],
424
'L_SKIP' => $lang['SKIP'],
425
'PAGE_TITLE' => $this->get_page_title(),
426
'T_IMAGE_PATH' => $phpbb_root_path . 'adm/images/',
428
'S_CONTENT_DIRECTION' => $lang['DIRECTION'],
429
'S_CONTENT_FLOW_BEGIN' => ($lang['DIRECTION'] == 'ltr') ? 'left' : 'right',
430
'S_CONTENT_FLOW_END' => ($lang['DIRECTION'] == 'ltr') ? 'right' : 'left',
431
'S_CONTENT_ENCODING' => 'UTF-8',
433
'S_USER_LANG' => $lang['USER_LANG'],
437
header('Content-type: text/html; charset=UTF-8');
438
header('Cache-Control: private, no-cache="set-cookie"');
439
header('Expires: 0');
440
header('Pragma: no-cache');
446
* Output the standard page footer
448
function page_footer()
450
global $db, $template;
452
$template->display('body');
454
// Close our DB connection.
455
if (!empty($db) && is_object($db))
460
if (function_exists('exit_handler'))
467
* Returns desired template name
469
function get_tpl_name()
471
return $this->module->tpl_name . '.html';
475
* Returns the desired page title
477
function get_page_title()
481
if (!isset($this->module->page_title))
486
return (isset($lang[$this->module->page_title])) ? $lang[$this->module->page_title] : $this->module->page_title;
490
* Generate an HTTP/1.1 header to redirect the user to another page
491
* This is used during the installation when we do not have a database available to call the normal redirect function
492
* @param string $page The page to redirect to relative to the installer root path
494
function redirect($page)
496
$server_name = (!empty($_SERVER['SERVER_NAME'])) ? $_SERVER['SERVER_NAME'] : getenv('SERVER_NAME');
497
$server_port = (!empty($_SERVER['SERVER_PORT'])) ? (int) $_SERVER['SERVER_PORT'] : (int) getenv('SERVER_PORT');
498
$secure = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 1 : 0;
500
$script_name = (!empty($_SERVER['PHP_SELF'])) ? $_SERVER['PHP_SELF'] : getenv('PHP_SELF');
503
$script_name = (!empty($_SERVER['REQUEST_URI'])) ? $_SERVER['REQUEST_URI'] : getenv('REQUEST_URI');
506
// Replace backslashes and doubled slashes (could happen on some proxy setups)
507
$script_name = str_replace(array('\\', '//'), '/', $script_name);
508
$script_path = trim(dirname($script_name));
510
$url = (($secure) ? 'https://' : 'http://') . $server_name;
512
if ($server_port && (($secure && $server_port <> 443) || (!$secure && $server_port <> 80)))
514
$url .= ':' . $server_port;
517
$url .= $script_path . '/' . $page;
518
header('Location: ' . $url);
523
* Generate the navigation tabs
525
function generate_navigation()
527
global $lang, $template, $phpEx, $language;
529
if (is_array($this->module_ary))
531
@ksort($this->module_ary);
532
foreach ($this->module_ary as $cat_ary)
534
$cat = $cat_ary['name'];
535
$l_cat = (!empty($lang['CAT_' . $cat])) ? $lang['CAT_' . $cat] : preg_replace('#_#', ' ', $cat);
536
$cat = strtolower($cat);
537
$url = $this->module_url . "?mode=$cat&language=$language";
539
if ($this->mode == $cat)
541
$template->assign_block_vars('t_block1', array(
543
'S_SELECTED' => true,
547
if (is_array($this->module_ary[$this->id]['subs']))
549
$subs = $this->module_ary[$this->id]['subs'];
550
foreach ($subs as $option)
552
$l_option = (!empty($lang['SUB_' . $option])) ? $lang['SUB_' . $option] : preg_replace('#_#', ' ', $option);
553
$option = strtolower($option);
554
$url = $this->module_url . '?mode=' . $this->mode . "&sub=$option&language=$language";
556
$template->assign_block_vars('l_block1', array(
557
'L_TITLE' => $l_option,
558
'S_SELECTED' => ($this->sub == $option),
564
if (is_array($this->module_ary[$this->id]['stages']))
566
$subs = $this->module_ary[$this->id]['stages'];
568
foreach ($subs as $option)
570
$l_option = (!empty($lang['STAGE_' . $option])) ? $lang['STAGE_' . $option] : preg_replace('#_#', ' ', $option);
571
$option = strtolower($option);
572
$matched = ($this->sub == $option) ? true : $matched;
574
$template->assign_block_vars('l_block2', array(
575
'L_TITLE' => $l_option,
576
'S_SELECTED' => ($this->sub == $option),
577
'S_COMPLETE' => !$matched,
584
$template->assign_block_vars('t_block1', array(
586
'S_SELECTED' => false,
595
* Output an error message
596
* If skip is true, return and continue execution, else exit
598
function error($error, $line, $file, $skip = false)
600
global $lang, $db, $template;
604
$template->assign_block_vars('checks', array(
606
'LEGEND' => $lang['INST_ERR'],
609
$template->assign_block_vars('checks', array(
610
'TITLE' => basename($file) . ' [ ' . $line . ' ]',
611
'RESULT' => '<b style="color:red">' . $error . '</b>',
617
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">';
618
echo '<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr">';
620
echo '<meta http-equiv="content-type" content="text/html; charset=utf-8" />';
621
echo '<title>' . $lang['INST_ERR_FATAL'] . '</title>';
622
echo '<link href="../adm/style/admin.css" rel="stylesheet" type="text/css" media="screen" />';
624
echo '<body id="errorpage">';
625
echo '<div id="wrap">';
626
echo ' <div id="page-header">';
628
echo ' <div id="page-body">';
629
echo ' <div id="acp">';
630
echo ' <div class="panel">';
631
echo ' <span class="corners-top"><span></span></span>';
632
echo ' <div id="content">';
633
echo ' <h1>' . $lang['INST_ERR_FATAL'] . '</h1>';
634
echo ' <p>' . $lang['INST_ERR_FATAL'] . "</p>\n";
635
echo ' <p>' . basename($file) . ' [ ' . $line . " ]</p>\n";
636
echo ' <p><b>' . $error . "</b></p>\n";
638
echo ' <span class="corners-bottom"><span></span></span>';
642
echo ' <div id="page-footer">';
643
echo ' Powered by phpBB © 2000, 2002, 2005, 2007 <a href="http://www.phpbb.com/">phpBB Group</a>';
649
if (!empty($db) && is_object($db))
658
* Output an error message for a database related problem
659
* If skip is true, return and continue execution, else exit
661
function db_error($error, $sql, $line, $file, $skip = false)
663
global $lang, $db, $template;
667
$template->assign_block_vars('checks', array(
669
'LEGEND' => $lang['INST_ERR_FATAL'],
672
$template->assign_block_vars('checks', array(
673
'TITLE' => basename($file) . ' [ ' . $line . ' ]',
674
'RESULT' => '<b style="color:red">' . $error . '</b><br />» SQL:' . $sql,
680
$template->set_filenames(array(
681
'body' => 'install_error.html')
683
$this->page_header();
684
$this->generate_navigation();
686
$template->assign_vars(array(
687
'MESSAGE_TITLE' => $lang['INST_ERR_FATAL_DB'],
688
'MESSAGE_TEXT' => '<p>' . basename($file) . ' [ ' . $line . ' ]</p><p>SQL : ' . $sql . '</p><p><b>' . $error . '</b></p>',
691
// Rollback if in transaction
692
if ($db->transaction)
694
$db->sql_transaction('rollback');
697
$this->page_footer();
701
* Generate the relevant HTML for an input field and the associated label and explanatory text
703
function input_field($name, $type, $value='', $options='')
706
$tpl_type = explode(':', $type);
709
switch ($tpl_type[0])
713
$size = (int) $tpl_type[1];
714
$maxlength = (int) $tpl_type[2];
716
$tpl = '<input id="' . $name . '" type="' . $tpl_type[0] . '"' . (($size) ? ' size="' . $size . '"' : '') . ' maxlength="' . (($maxlength) ? $maxlength : 255) . '" name="' . $name . '" value="' . $value . '" />';
720
$rows = (int) $tpl_type[1];
721
$cols = (int) $tpl_type[2];
723
$tpl = '<textarea id="' . $name . '" name="' . $name . '" rows="' . $rows . '" cols="' . $cols . '">' . $value . '</textarea>';
727
$key_yes = ($value) ? ' checked="checked" id="' . $name . '"' : '';
728
$key_no = (!$value) ? ' checked="checked" id="' . $name . '"' : '';
730
$tpl_type_cond = explode('_', $tpl_type[1]);
731
$type_no = ($tpl_type_cond[0] == 'disabled' || $tpl_type_cond[0] == 'enabled') ? false : true;
733
$tpl_no = '<label><input type="radio" name="' . $name . '" value="0"' . $key_no . ' class="radio" /> ' . (($type_no) ? $lang['NO'] : $lang['DISABLED']) . '</label>';
734
$tpl_yes = '<label><input type="radio" name="' . $name . '" value="1"' . $key_yes . ' class="radio" /> ' . (($type_no) ? $lang['YES'] : $lang['ENABLED']) . '</label>';
736
$tpl = ($tpl_type_cond[0] == 'yes' || $tpl_type_cond[0] == 'enabled') ? $tpl_yes . ' ' . $tpl_no : $tpl_no . ' ' . $tpl_yes;
740
eval('$s_options = ' . str_replace('{VALUE}', $value, $options) . ';');
741
$tpl = '<select id="' . $name . '" name="' . $name . '">' . $s_options . '</select>';
745
eval('$tpl = ' . str_replace('{VALUE}', $value, $options) . ';');
756
* Generate the drop down of available language packs
758
function inst_language_select($default = '')
760
global $phpbb_root_path, $phpEx;
762
$dir = @opendir($phpbb_root_path . 'language');
766
$this->error('Unable to access the language directory', __LINE__, __FILE__);
769
while ($file = readdir($dir))
771
$path = $phpbb_root_path . 'language/' . $file;
773
if ($file == '.' || $file == '..' || is_link($path) || is_file($path) || $file == 'CVS')
778
if (file_exists($path . '/iso.txt'))
780
list($displayname, $localname) = @file($path . '/iso.txt');
781
$lang[$localname] = $file;
790
foreach ($lang as $displayname => $filename)
792
$selected = (strtolower($default) == strtolower($filename)) ? ' selected="selected"' : '';
793
$user_select .= '<option value="' . $filename . '"' . $selected . '>' . ucwords($displayname) . '</option>';
b'\\ No newline at end of file'