phpBB
Statistics
| Revision:

root / tags / release_2_0_1 / phpBB / install.php

History | View | Annotate | Download (32.8 kB)

1
<?php
2
/***************************************************************************
3
 *                                install.php
4
 *                            -------------------
5
 *   begin                : Tuesday, Sept 11, 2001
6
 *   copyright            : (C) 2001 The phpBB Group
7
 *   email                : supportphpbb.com
8
 *
9
 *   $Id: install.php 2610 2002-05-20 13:52:12Z  $
10
 *
11
 ***************************************************************************/
12
13
/***************************************************************************
14
 *
15
 *   This program is free software; you can redistribute it and/or modify
16
 *   it under the terms of the GNU General Public License as published by
17
 *   the Free Software Foundation; either version 2 of the License, or
18
 *   (at your option) any later version.
19
 *
20
 ***************************************************************************/
21
22
error_reporting  (E_ERROR | E_WARNING | E_PARSE); // This will NOT report uninitialized variables
23
set_magic_quotes_runtime(0); // Disable magic_quotes_runtime
24
25
define('IN_PHPBB', true);
26
$phpbb_root_path='./';
27
include($phpbb_root_path.'extension.inc');
28
include($phpbb_root_dir . 'includes/functions_selects.'.$phpEx);
29
30
$userdata = array();
31
$lang = array();
32
$reinstall = false;
33
34
if( !get_magic_quotes_gpc() )
35
{
36
        if( is_array($HTTP_GET_VARS) )
37
        {
38
                while( list($k, $v) = each($HTTP_GET_VARS) )
39
                {
40
                        if( is_array($HTTP_GET_VARS[$k]) )
41
                        {
42
                                while( list($k2, $v2) = each($HTTP_GET_VARS[$k]) )
43
                                {
44
                                        $HTTP_GET_VARS[$k][$k2] = addslashes($v2);
45
                                }
46
                                @reset($HTTP_GET_VARS[$k]);
47
                        }
48
                        else
49
                        {
50
                                $HTTP_GET_VARS[$k] = addslashes($v);
51
                        }
52
                }
53
                @reset($HTTP_GET_VARS);
54
        }
55
56
        if( is_array($HTTP_POST_VARS) )
57
        {
58
                while( list($k, $v) = each($HTTP_POST_VARS) )
59
                {
60
                        if( is_array($HTTP_POST_VARS[$k]) )
61
                        {
62
                                while( list($k2, $v2) = each($HTTP_POST_VARS[$k]) )
63
                                {
64
                                        $HTTP_POST_VARS[$k][$k2] = addslashes($v2);
65
                                }
66
                                @reset($HTTP_POST_VARS[$k]);
67
                        }
68
                        else
69
                        {
70
                                $HTTP_POST_VARS[$k] = addslashes($v);
71
                        }
72
                }
73
                @reset($HTTP_POST_VARS);
74
        }
75
76
        if( is_array($HTTP_COOKIE_VARS) )
77
        {
78
                while( list($k, $v) = each($HTTP_COOKIE_VARS) )
79
                {
80
                        if( is_array($HTTP_COOKIE_VARS[$k]) )
81
                        {
82
                                while( list($k2, $v2) = each($HTTP_COOKIE_VARS[$k]) )
83
                                {
84
                                        $HTTP_COOKIE_VARS[$k][$k2] = addslashes($v2);
85
                                }
86
                                @reset($HTTP_COOKIE_VARS[$k]);
87
                        }
88
                        else
89
                        {
90
                                $HTTP_COOKIE_VARS[$k] = addslashes($v);
91
                        }
92
                }
93
                @reset($HTTP_COOKIE_VARS);
94
        }
95
}
96
97
/***************************************************************************
98
 *                                Install Customization Section
99
 *
100
 *        This section can be modified to set up some basic default information
101
 *         used by the install script.  Specifically the default theme data
102
 *        and the default template.
103
 *
104
 **************************************************************************/
105
106
$default_language = 'english';
107
$default_template = 'subSilver';
108
109
$available_dbms = array(
110
        "mysql" => array(
111
                "LABEL" => "MySQL 3.x",
112
                "SCHEMA" => "mysql", 
113
                "DELIM" => ";",
114
                "DELIM_BASIC" => ";",
115
                "COMMENTS" => "remove_remarks"
116
        ), 
117
        "mysql4" => array(
118
                "LABEL" => "MySQL 4.x",
119
                "SCHEMA" => "mysql", 
120
                "DELIM" => ";", 
121
                "DELIM_BASIC" => ";",
122
                "COMMENTS" => "remove_remarks"
123
        ), 
124
        "postgres" => array(
125
                "LABEL" => "PostgreSQL 7.x",
126
                "SCHEMA" => "postgres", 
127
                "DELIM" => ";", 
128
                "DELIM_BASIC" => ";",
129
                "COMMENTS" => "remove_comments"
130
        ), 
131
        "mssql" => array(
132
                "LABEL" => "MS SQL Server 7/2000",
133
                "SCHEMA" => "mssql", 
134
                "DELIM" => "GO", 
135
                "DELIM_BASIC" => ";",
136
                "COMMENTS" => "remove_comments"
137
        ),
138
        "msaccess" => array(
139
                "LABEL" => "MS Access [ ODBC ]",
140
                "SCHEMA" => "", 
141
                "DELIM" => "", 
142
                "DELIM_BASIC" => ";",
143
                "COMMENTS" => ""
144
        ),
145
        "mssql-odbc" =>        array(
146
                "LABEL" => "MS SQL Server [ ODBC ]",
147
                "SCHEMA" => "mssql", 
148
                "DELIM" => "GO",
149
                "DELIM_BASIC" => ";",
150
                "COMMENTS" => "remove_comments"
151
        )
152
);
153
154
//
155
// drop table schema
156
//
157
$sql_array = array();
158
159
$sql_array['drop_schema'][] = "DROP TABLE phpbb_auth_access";
160
$sql_array['drop_schema'][] = "DROP TABLE phpbb_banlist";
161
$sql_array['drop_schema'][] = "DROP TABLE phpbb_categories";
162
$sql_array['drop_schema'][] = "DROP TABLE phpbb_config";
163
$sql_array['drop_schema'][] = "DROP TABLE phpbb_disallow";
164
$sql_array['drop_schema'][] = "DROP TABLE phpbb_forum_prune";
165
$sql_array['drop_schema'][] = "DROP TABLE phpbb_forums";
166
$sql_array['drop_schema'][] = "DROP TABLE phpbb_groups";
167
$sql_array['drop_schema'][] = "DROP TABLE phpbb_posts";
168
$sql_array['drop_schema'][] = "DROP TABLE phpbb_posts_text";
169
$sql_array['drop_schema'][] = "DROP TABLE phpbb_privmsgs";
170
$sql_array['drop_schema'][] = "DROP TABLE phpbb_privmsgs_text";
171
$sql_array['drop_schema'][] = "DROP TABLE phpbb_ranks";
172
$sql_array['drop_schema'][] = "DROP TABLE phpbb_search_results";
173
$sql_array['drop_schema'][] = "DROP TABLE phpbb_search_wordlist";
174
$sql_array['drop_schema'][] = "DROP TABLE phpbb_search_wordmatch";
175
$sql_array['drop_schema'][] = "DROP TABLE phpbb_sessions";
176
$sql_array['drop_schema'][] = "DROP TABLE phpbb_smilies";
177
$sql_array['drop_schema'][] = "DROP TABLE phpbb_themes";
178
$sql_array['drop_schema'][] = "DROP TABLE phpbb_themes_name";
179
$sql_array['drop_schema'][] = "DROP TABLE phpbb_topics";
180
$sql_array['drop_schema'][] = "DROP TABLE phpbb_topics_watch";
181
$sql_array['drop_schema'][] = "DROP TABLE phpbb_user_group";
182
$sql_array['drop_schema'][] = "DROP TABLE phpbb_users";
183
$sql_array['drop_schema'][] = "DROP TABLE phpbb_vote_desc";
184
$sql_array['drop_schema'][] = "DROP TABLE phpbb_vote_results";
185
$sql_array['drop_schema'][] = "DROP TABLE phpbb_vote_voters";
186
$sql_array['drop_schema'][] = "DROP TABLE phpbb_words";
187
188
//
189
// Uncomment the following line to completely disable the ftp option...
190
//
191
// define('NO_FTP', true);
192
193
/***************************************************************************
194
*                
195
*                                                End Install Customization Section
196
*
197
***************************************************************************/
198
199
//
200
// Obtain various vars
201
//
202
$confirm = ( isset($HTTP_POST_VARS['confirm']) ) ? true : false;
203
$cancel = ( isset($HTTP_POST_VARS['cancel']) ) ? true : false;
204
205
if( isset($HTTP_POST_VARS['install_step']) || isset($HTTP_GET_VARS['install_step']) )
206
{
207
        $install_step = ( isset($HTTP_POST_VARS['install_step']) ) ? $HTTP_POST_VARS['install_step'] : $HTTP_GET_VARS['install_step'];
208
}
209
else
210
{
211
        $install_step = "";
212
}
213
214
$upgrade = ( !empty($HTTP_POST_VARS['upgrade']) ) ? $HTTP_POST_VARS['upgrade']: '';
215
$upgrade_now = ( !empty($HTTP_POST_VARS['upgrade_now']) ) ? $HTTP_POST_VARS['upgrade_now']:'';
216
217
$dbms = isset($HTTP_POST_VARS['dbms']) ? $HTTP_POST_VARS['dbms'] : "";
218
$language = ( !empty($HTTP_POST_VARS['language']) ) ? $HTTP_POST_VARS['language'] : $default_language;
219
220
$dbhost = ( !empty($HTTP_POST_VARS['dbhost']) ) ? $HTTP_POST_VARS['dbhost'] : "";
221
$dbuser = ( !empty($HTTP_POST_VARS['dbuser']) ) ? $HTTP_POST_VARS['dbuser'] : "";
222
$dbpasswd = ( !empty($HTTP_POST_VARS['dbpasswd']) ) ? $HTTP_POST_VARS['dbpasswd'] : "";
223
$dbname = ( !empty($HTTP_POST_VARS['dbname']) ) ? $HTTP_POST_VARS['dbname'] : "";
224
225
$table_prefix = ( !empty($HTTP_POST_VARS['prefix']) ) ? $HTTP_POST_VARS['prefix'] : "";
226
227
$admin_name = ( !empty($HTTP_POST_VARS['admin_name']) ) ? $HTTP_POST_VARS['admin_name'] : "";
228
$admin_pass1 = ( !empty($HTTP_POST_VARS['admin_pass1']) ) ? $HTTP_POST_VARS['admin_pass1'] : "";
229
$admin_pass2 = ( !empty($HTTP_POST_VARS['admin_pass2']) ) ? $HTTP_POST_VARS['admin_pass2'] : "";
230
231
$ftp_path = ( !empty($HTTP_POST_VARS['ftp_path']) ) ? $HTTP_POST_VARS['ftp_path'] : "";
232
$ftp_user = ( !empty($HTTP_POST_VARS['ftp_user']) ) ? $HTTP_POST_VARS['ftp_user'] : "";
233
$ftp_pass = ( !empty($HTTP_POST_VARS['ftp_pass']) ) ? $HTTP_POST_VARS['ftp_pass'] : "";
234
235
$server_name = ( !empty($HTTP_POST_VARS['server_name']) ) ? $HTTP_POST_VARS['server_name'] : "";
236
$server_port = ( !empty($HTTP_POST_VARS['server_port']) ) ? $HTTP_POST_VARS['server_port'] : "";
237
$board_email = ( !empty($HTTP_POST_VARS['board_email']) ) ? $HTTP_POST_VARS['board_email'] : "";
238
$script_path = ( !empty($HTTP_POST_VARS['script_path']) ) ? $HTTP_POST_VARS['script_path'] : "";
239
240
if( @file_exists('config.'.$phpEx) )
241
{
242
        include('config.'.$phpEx);
243
}
244
245
if( !defined("PHPBB_INSTALLED") )
246
{
247
        include($phpbb_root_path.'includes/sql_parse.'.$phpEx);
248
        include($phpbb_root_path.'includes/constants.'.$phpEx);
249
        include($phpbb_root_path.'includes/template.'.$phpEx);
250
        include($phpbb_root_path.'includes/functions.'.$phpEx);
251
        include($phpbb_root_path.'includes/sessions.'.$phpEx);
252
253
        //
254
        // Import language file, setup template ...
255
        //
256
        include($phpbb_root_path.'language/lang_' . $language . '/lang_main.'.$phpEx);
257
        include($phpbb_root_path.'language/lang_' . $language . '/lang_admin.'.$phpEx);
258
259
        $template = new Template($phpbb_root_path . "templates/" . $default_template);
260
261
        //
262
        // Ok for the time being I'm commenting this out whilst I'm working on
263
        // better integration of the install with upgrade as per Bart's request
264
        // JLH
265
        //
266
        
267
        if( $upgrade == 1 )
268
        {
269
                // require('upgrade.'.$phpEx);
270
                $install_step = 1;
271
        }
272
        
273
        //
274
        // Load default template for install
275
        // 
276
        $template->set_filenames(array(
277
                "body" => "install.tpl")
278
        );
279
280
        $template->assign_vars(array(
281
                "L_INSTALLATION" => $lang['Welcome_install'])
282
        );
283
}
284
else
285
{
286
        define("IN_ADMIN", 1);
287
288
        include($phpbb_root_path.'common.'.$phpEx);
289
        include($phpbb_root_path.'includes/sql_parse.'.$phpEx);
290
291
        //
292
        // Set page ID for session management
293
        //
294
        $userdata = session_pagestart($user_ip, PAGE_INDEX, $session_length);
295
        init_userprefs($userdata);
296
        //
297
        // End session management
298
        //
299
300
        if( $userdata['user_level'] == ADMIN && !$cancel && $dbms != 'msaccess' )
301
        {
302
                if( !$confirm )
303
                {
304
                        //
305
                        // Sorry this has already been installed can't do anything more with it
306
                        //
307
                        include($phpbb_root_path . 'includes/page_header.'.$phpEx);
308
309
                        $template->set_filenames(array(
310
                                "confirm" => "confirm_body.tpl")
311
                        );
312
313
                        $template->assign_vars(array(
314
                                "MESSAGE_TITLE" => $lang['Admin_config'],
315
                                "MESSAGE_TEXT" => $lang['Re_install'],
316
317
                                "L_YES" => $lang['Yes'],
318
                                "L_NO" => $lang['No'],
319
320
                                "S_CONFIRM_ACTION" => append_sid("install.$phpEx"),
321
                                "S_HIDDEN_FIELDS" => $hidden_fields)
322
                        );
323
324
                        $template->pparse("confirm");
325
326
                        include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
327
                }
328
329
                include($phpbb_root_path.'language/lang_' . $language . '/lang_main.'.$phpEx);
330
                include($phpbb_root_path.'language/lang_' . $language . '/lang_admin.'.$phpEx);
331
332
                $template = new Template($phpbb_root_path . "templates/" . $default_template);
333
334
                $template->set_filenames(array(
335
                        "body" => "install.tpl")
336
                );
337
338
                $template->assign_vars(array(
339
                        "L_INSTALLATION" => $lang['Welcome_install'])
340
                );
341
342
                $reinstall = true;
343
        }
344
        else
345
        {
346
                header("Location: " . append_sid("index.$phpEx", true));
347
                exit;
348
        }
349
}
350
351
//
352
//
353
//
354
if( !empty($HTTP_POST_VARS['send_file']) && $HTTP_POST_VARS['send_file'] == 1  && !defined("PHPBB_INSTALLED") && empty($HTTP_POST_VARS['upgrade_now']) )
355
{
356
        header("Content-Type: text/x-delimtext; name=\"config.$phpEx\"");
357
        header("Content-disposition: attachment; filename=config.$phpEx");
358
359
        //
360
        // We need to stripslashes no matter what the setting of magic_quotes_gpc is
361
        // because we add slahes at the top if its off, and they are added automaticlly 
362
        // if it is on.
363
        //
364
        $HTTP_POST_VARS['config_data'] = stripslashes($HTTP_POST_VARS['config_data']);
365
366
        echo $HTTP_POST_VARS['config_data'];
367
368
        exit;
369
}
370
else if( !empty($HTTP_POST_VARS['send_file']) && $HTTP_POST_VARS['send_file'] == 2 && !defined("PHPBB_INSTALLED")  )
371
{
372
        //
373
        // Ok we couldn't write the config file so let's try ftping it.
374
        //
375
376
        $HTTP_POST_VARS['config_data'] = stripslashes($HTTP_POST_VARS['config_data']);
377
378
        $s_hidden_fields = '<input type="hidden" name="config_data" value="' . htmlspecialchars($HTTP_POST_VARS['config_data']) . '" />';
379
        $s_hidden_fields .= '<input type="hidden" name="ftp_file" value="1" />';
380
381
        if( $upgrade == 1 )
382
        {
383
                $s_hidden_fields .= '<input type="hidden" name="upgrade" value="1" />';
384
        }
385
386
        $template->assign_block_vars("switch_ftp_file", array());
387
        $template->assign_block_vars("switch_common_install", array());
388
389
        $template->assign_vars(array(
390
                "L_INSTRUCTION_TEXT" => $lang['ftp_instructs'],
391
                "L_FTP_INFO" => $lang['ftp_info'],
392
                "L_FTP_PATH" => $lang['ftp_path'],
393
                "L_FTP_PASS" => $lang['ftp_password'],
394
                "L_FTP_USER" => $lang['ftp_username'],
395
                "L_SUBMIT" => $lang['Transfer_config'],
396
397
                "S_HIDDEN_FIELDS" => $s_hidden_fields, 
398
                "S_FORM_ACTION" => "install.$phpEx")
399
        );
400
401
        $template->pparse("body");
402
403
        exit;
404
405
}
406
else if( !empty($HTTP_POST_VARS['ftp_file']) && !defined("PHPBB_INSTALLED")  )
407
{
408
        //
409
        // Here we'll actually send the file...
410
        //
411
        $HTTP_POST_VARS['config_data'] = stripslashes($HTTP_POST_VARS['config_data']);
412
        
413
        $conn_id = @ftp_connect('localhost');
414
        $login_result = @ftp_login($conn_id, "$ftp_user", "$ftp_pass");
415
416
        if( !$conn_id || !$login_result )
417
        {
418
                //
419
                // Error couldn't get connected... Go back to option to send file...
420
                //
421
                $s_hidden_fields = '<input type="hidden" name="config_data" value="' . htmlspecialchars($HTTP_POST_VARS['config_data']) . '" />';
422
                $s_hidden_fields .= '<input type="hidden" name="send_file" value="1" />';
423
                if( $upgrade == 1 )
424
                {
425
                        $s_hidden_fields .= '<input type="hidden" name="upgrade" value="1" />';
426
                        $s_hidden_fields .= '<input type="hidden" name="dbms" value="'.$dmbs.'" />';
427
                        $s_hidden_fields .= '<input type="hidden" name="prefix" value="'.$table_prefix.'" />';
428
                        $s_hidden_fields .= '<input type="hidden" name="dbhost" value="'.$dbhost.'" />';
429
                        $s_hidden_fields .= '<input type="hidden" name="dbname" value="'.$dbname.'" />';
430
                        $s_hidden_fields .= '<input type="hidden" name="dbuser" value="'.$dbuser.'" />';
431
                        $s_hidden_fields .= '<input type="hidden" name="dbpasswd" value="'.$dbpasswd.'" />';
432
                        $s_hidden_fields .= '<input type="hidden" name="install_step" value="1" />';
433
                        $s_hidden_fields .= '<input type="hidden" name="admin_pass1" value="1" />';
434
                        $s_hidden_fields .= '<input type="hidden" name="admin_pass2" value="1" />';
435
                        $s_hidden_fields .= '<input type="hidden" name="server_port" value="'.$server_port.'" />';
436
                        $s_hidden_fields .= '<input type="hidden" name="server_name" value="'.$server_name.'" />';
437
                        $s_hidden_fields .= '<input type="hidden" name="script_path" value="'.$script_path.'" />';
438
                        $s_hidden_fields .= '<input type="hidden" name="board_email" value="'.$board_email.'" />';
439
                        $template->assign_block_vars("switch_upgrade_install", array());
440
                        $template->assign_vars(array(
441
                                "L_UPGRADE_INST" => $lang['continue_upgrade'],
442
                                "L_UPGRADE_SUBMIT" => $lang['upgrade_submit'])
443
                        );
444
                }
445
                $template->assign_block_vars("switch_common_install", array());
446
                
447
                $template->assign_vars(array(
448
                        "L_INSTRUCTION_TEXT" => $lang['NoFTP_config'],
449
                        "L_SUBMIT" => $lang['Download_config'],
450
451
                        "S_HIDDEN_FIELDS" => $s_hidden_fields, 
452
                        "S_FORM_ACTION" => "install.$phpEx")
453
                );
454
455
                $template->pparse('body');
456
457
                exit;
458
        }
459
        else
460
        {
461
                //
462
                // Write out a temp file...
463
                //
464
                $tmpfname = @tempnam('/tmp', 'cfg');
465
466
                @unlink($tmpfname); // unlink for safety on php4.0.3+
467
468
                $fp = @fopen($tmpfname, 'w');
469
470
                @fwrite($fp, $HTTP_POST_VARS['config_data']);
471
472
                @fclose($fp);
473
474
                //
475
                // Now ftp it across.
476
                //
477
                @ftp_chdir($conn_id, $ftp_dir);
478
479
                $res = ftp_put($conn_id, 'config.'.$phpEx, $tmpfname, FTP_ASCII);
480
481
                @ftp_quit($conn_id);
482
483
                unlink($tmpfname);
484
                if( $upgrade == 1 )        
485
                {
486
                        require('upgrade.'.$phpEx);
487
                        exit;
488
                }
489
                //
490
                // Ok we are basically done with the install process let's go on 
491
                // and let the user configure their board now.
492
                //
493
                // We are going to do this by calling the admin_board.php from the
494
                // normal board admin section.
495
                //
496
                $s_hidden_fields = '<input type="hidden" name="username" value="' . $admin_name . '" />';
497
                $s_hidden_fields .= '<input type="hidden" name="password" value="' . $admin_pass1 . '" />';
498
                $s_hidden_fields .= '<input type="hidden" name="redirect" value="admin/index.php" />';
499
                $s_hidden_fields .= '<input type="hidden" name="submit" value="' . $lang['Login'] . '" />';
500
501
                $template->assign_block_vars("switch_common_install", array());
502
503
                $template->assign_vars(array(
504
                        "L_INSTRUCTION_TEXT" => $lang['Inst_Step_2'],
505
                        "L_SUBMIT" => $lang['Finish_Install'],
506
507
                        "S_HIDDEN_FIELDS" => $s_hidden_fields, 
508
                        "S_FORM_ACTION" => "login.$phpEx")
509
                );
510
                
511
                $template->pparse('body');
512
513
                exit();
514
        }
515
}
516
else if( ( empty($install_step) || $admin_pass1 != $admin_pass2 || empty($admin_pass1) || $dbhost == "" )  && !defined("PHPBB_INSTALLED") )
517
{        //
518
        // Ok we haven't installed before so lets work our way through the various
519
        // steps of the install process.  This could turn out to be quite a lengty 
520
        // process.
521
        //
522
523
        //
524
        // Step 0 gather the pertinant info for database setup...
525
        // Namely dbms, dbhost, dbname, dbuser, and dbpasswd.
526
        //
527
528
        //
529
        // Guess at some basic info used for install..
530
        //
531
        
532
        if ( !empty($HTTP_SERVER_VARS['SERVER_NAME']) || !empty($HTTP_ENV_VARS['SERVER_NAME']) )
533
        {
534
                $server_name = ( !empty($HTTP_SERVER_VARS['SERVER_NAME']) ) ? $HTTP_SERVER_VARS['SERVER_NAME'] : $HTTP_ENV_VARS['SERVER_NAME'];
535
        }
536
        else if ( !empty($HTTP_SERVER_VARS['HTTP_HOST']) || !empty($HTTP_ENV_VARS['HTTP_HOST']) )
537
        {
538
                $server_name = ( !empty($HTTP_SERVER_VARS['HTTP_HOST']) ) ? $HTTP_SERVER_VARS['HTTP_HOST'] : $HTTP_ENV_VARS['HTTP_HOST'];
539
        }
540
        else
541
        {
542
                $server_name = '';
543
        }
544
        if ( !empty($HTTP_SERVER_VARS['SERVER_PORT']) || !empty($HTTP_ENV_VARS['SERVER_PORT']) )
545
        {
546
                $server_port = ( !empty($HTTP_SERVER_VARS['SERVER_PORT']) ) ? $HTTP_SERVER_VARS['SERVER_PORT'] : $HTTP_ENV_VARS['SERVER_PORT'];
547
        }
548
        else
549
        {
550
                $server_port = '80';
551
        }
552
        $script_path = preg_replace('/install\.'.$phpEx.'/i', '', $HTTP_SERVER_VARS['PHP_SELF']);
553
554
        $instruction_text = $lang['Inst_Step_0'];
555
556
        if( (($HTTP_POST_VARS['admin_pass1'] != $HTTP_POST_VARS['admin_pass2']) && $install_step != '0') || (empty($HTTP_POST_VARS['admin_pass1']) && !empty($dbhost)))
557
        {
558
                $instruction_text = $lang['Password_mismatch'] . '<br />' . $instruction_text;
559
        }
560
561
        $lang_options = language_select($language, 'language');
562
563
        $dbms_options = '<select name="dbms" onchange="if(document.install_form.upgrade.options[upgrade.selectedIndex].value == 1) { document.install_form.dbms.selectedIndex=0}">';
564
        while( list($dbms_name, $details) = @each($available_dbms) )
565
        {
566
                $selected = ( $dbms_name == $dbms ) ? "selected=\"selected\"" : "";
567
                $dbms_options .= '<option value="' . $dbms_name . '">' . $details['LABEL'] . '</option>';
568
        }
569
        $dbms_options .= '</select>';
570
571
        $upgrade_option = '<select name="upgrade"';
572
        $upgrade_option .= 'onchange="if( this.options[this.selectedIndex].value == 1 ) { document.install_form.dbms.selectedIndex=0; }">';
573
        $upgrade_option .= '<option value="0">' . $lang['Install'] . '</option>';
574
        $upgrade_option .= '<option value="1">' . $lang['Upgrade'] . '</option></select>';
575
        
576
        $s_hidden_fields = '<input type="hidden" name="install_step" value="1" />';
577
578
        $template->assign_block_vars("switch_stage_one_install", array());
579
        $template->assign_block_vars("switch_common_install", array());
580
581
        $template->assign_vars(array(
582
                "L_INSTRUCTION_TEXT" => $instruction_text,
583
                "L_INITIAL_CONFIGURATION" => $lang['Initial_config'], 
584
                "L_DATABASE_CONFIGURATION" => $lang['DB_config'], 
585
                "L_ADMIN_CONFIGURATION" => $lang['Admin_config'], 
586
                "L_LANGUAGE" => $lang['Default_lang'], 
587
                "L_DBMS" => $lang['dbms'], 
588
                "L_DB_HOST" => $lang['DB_Host'], 
589
                "L_DB_NAME" => $lang['DB_Name'], 
590
                "L_DB_USER" => $lang['DB_Username'], 
591
                "L_DB_PASSWORD" => $lang['DB_Password'], 
592
                "L_DB_PREFIX" => $lang['Table_Prefix'], 
593
                "L_UPGRADE" => $lang['Install_Method'],
594
                "L_ADMIN_USERNAME" => $lang['Admin_Username'], 
595
                "L_ADMIN_PASSWORD" => $lang['Admin_Password'], 
596
                "L_ADMIN_CONFIRM_PASSWORD" => $lang['Admin_Password_confirm'], 
597
                "L_SUBMIT" => $lang['Start_Install'], 
598
                "L_ADMIN_EMAIL" => $lang['Admin_email'],
599
                "L_SERVER_NAME" => $lang['Server_name'],
600
                "L_SERVER_PORT" => $lang['Server_port'],
601
                "L_SCRIPT_PATH" => $lang['Script_path'],
602
                
603
                "SCRIPT_PATH" => $script_path,
604
                "SERVER_PORT" => $server_port,
605
                "SERVER_NAME" => $server_name,
606
                "DB_PREFIX" => ( !empty($table_prefix) ) ? $table_prefix : "phpbb_", 
607
                "DB_HOST" => ( $dbhost != "" ) ? $dbhost : "", 
608
                "DB_USER" => ( $dbuser != "" ) ? $dbuser : "", 
609
                "DB_PASSWD" => ( $dbpasswd != "" ) ? $dbpasswd : "", 
610
                "ADMIN_USERNAME" => ( $admin_name != "" ) ? $admin_name : "", 
611
612
                "S_LANG_SELECT" => $lang_options, 
613
                "S_DBMS_SELECT" => $dbms_options, 
614
                "S_HIDDEN_FIELDS" => $s_hidden_fields,
615
                "S_UPGRADE_SELECT" => $upgrade_option,
616
                "S_FORM_ACTION" => "install.$phpEx")
617
        );
618
619
        $template->pparse("body");
620
621
        exit;
622
}
623
else
624
{
625
        //
626
        // Go ahead and create the DB, then populate it
627
        //
628
        // MS Access is slightly different in that a pre-built, pre-
629
        // populated DB is supplied, all we need do here is update
630
        // the relevant entries
631
        //
632
        if( $reinstall )
633
        {
634
                $sql_query = preg_replace('/phpbb_/', $table_prefix, $sql_array['drop_schema']);
635
                $sql_count = count($sql_query);
636
637
                for($i = 0; $i < $sql_count; $i++)
638
                {
639
                        $result = $db->sql_query($sql_query[$i]);
640
                        if( !$result )
641
                        {
642
                                $error = $db->sql_error();
643
644
                                $template->assign_block_vars("switch_error_install", array());
645
646
                                $template->assign_vars(array(
647
                                        "L_ERROR_TITLE" => $lang['Installer_Error'],
648
                                        "L_ERROR" => $lang['Install_db_error'] . '<br /><br />' . $error)
649
                                );
650
651
                                $template->pparse('body');
652
653
                                exit;
654
                        }
655
                }
656
657
                $admin_name = $userdata['username'];
658
                $admin_pass1 = $userdata['user_password'];
659
                $language = $userdata['user_lang'];
660
        }
661
        else if( isset($dbms) )
662
        {
663
                switch( $dbms )
664
                {
665
                        case 'msaccess':
666
                        case 'mssql-odbc':
667
                                $check_exts = 'odbc';
668
                                $check_other = 'odbc';
669
                                break;
670
                        case 'mssql':
671
                                $check_exts = 'mssql';
672
                                $check_other = 'sybase';
673
                                break;
674
                        case 'mysql':
675
                        case 'mysql4':
676
                                $check_exts = 'mysql';
677
                                $check_other = 'mysql';
678
                                break;
679
                        case 'postgres':
680
                                $check_exts = 'pgsql';
681
                                $check_other = 'pgsql';
682
                                break;
683
                }
684
                if( !extension_loaded( $check_exts ) && !extension_loaded( $check_other ) )
685
                {        
686
                        $template->assign_block_vars("switch_error_install", array());
687
688
                        $template->assign_vars(array(
689
                                "L_ERROR_TITLE" => $lang['Installer_Error'],
690
                                "L_ERROR" => $lang['Install_No_Ext'])
691
                        );
692
                        $template->pparse('body');                                
693
                        exit;
694
                }
695
                include($phpbb_root_path.'includes/db.'.$phpEx);
696
        }
697
698
        $dbms_schema = 'db/schemas/' . $available_dbms[$dbms]['SCHEMA'] . '_schema.sql';
699
        $dbms_basic = 'db/schemas/' . $available_dbms[$dbms]['SCHEMA'] . '_basic.sql';
700
701
        $remove_remarks = $available_dbms[$dbms]['COMMENTS'];;
702
        $delimiter = $available_dbms[$dbms]['DELIM']; 
703
        $delimiter_basic = $available_dbms[$dbms]['DELIM_BASIC']; 
704
705
        if( $install_step == 1 || $reinstall )
706
        {
707
                if( $upgrade != 1 )
708
                {
709
                        if( $dbms != 'msaccess' )
710
                        {
711
                                //
712
                                // Ok we have the db info go ahead and read in the relevant schema
713
                                // and work on building the table.. probably ought to provide some
714
                                // kind of feedback to the user as we are working here in order
715
                                // to let them know we are actually doing something.
716
                                //
717
                                $sql_query = @fread(@fopen($dbms_schema, 'r'), @filesize($dbms_schema));
718
                                $sql_query = preg_replace('/phpbb_/', $table_prefix, $sql_query);
719
720
                                $sql_query = $remove_remarks($sql_query);
721
                                $sql_query = split_sql_file($sql_query, $delimiter);
722
723
                                $sql_count = count($sql_query);
724
725
                                for($i = 0; $i < $sql_count; $i++)
726
                                {
727
                                        $result = $db->sql_query($sql_query[$i]);
728
                                        if( !$result )
729
                                        {
730
                                                $error = $db->sql_error();
731
                
732
                                                $template->assign_block_vars("switch_error_install", array());
733
734
                                                $template->assign_vars(array(
735
                                                        "L_ERROR_TITLE" => $lang['Installer_Error'],
736
                                                        "L_ERROR" => $lang['Install_db_error'] . '<br />' . $error['message'])
737
                                                );
738
739
                                                $template->pparse('body');
740
741
                                                exit;
742
                                        }
743
                                }
744
                
745
                                //
746
                                // Ok tables have been built, let's fill in the basic information
747
                                //
748
                                $sql_query = @fread(@fopen($dbms_basic, 'r'), @filesize($dbms_basic));
749
                                $sql_query = preg_replace('/phpbb_/', $table_prefix, $sql_query);
750
751
                                $sql_query = $remove_remarks($sql_query);
752
                                $sql_query = split_sql_file($sql_query, $delimiter_basic);
753
754
                                $sql_count = count($sql_query);
755
756
                                for($i = 0; $i < $sql_count; $i++)
757
                                {
758
                                        $result = $db->sql_query($sql_query[$i]);
759
                                        if( !$result )
760
                                        {
761
                                                $error = $db->sql_error();
762
                
763
                                                $template->assign_block_vars("switch_error_install", array());
764
765
                                                $template->assign_vars(array(
766
                                                        "L_ERROR_TITLE" => $lang['Installer_Error'],
767
                                                        "L_ERROR" => $lang['Install_db_error'] . "<br />" . $error["message"])
768
                                                );
769
770
                                                $template->pparse('body');
771
772
                                                exit;
773
                                        }
774
                                }
775
                        }
776
777
                        //
778
                        // Ok at this point they have entered their admin password, let's go 
779
                        // ahead and create the admin account with some basic default information
780
                        // that they can customize later, and write out the config file.  After
781
                        // this we are going to pass them over to the admin_forum.php script
782
                        // to set up their forum defaults.
783
                        //
784
                        $error = "";
785
786
                        //
787
                        // Update the default admin user with their information.
788
                        //
789
                        $sql = "INSERT INTO " . $table_prefix . "config (config_name, config_value) 
790
                                VALUES ('board_startdate', " . time() . ")";
791
                        $result = $db->sql_query($sql);
792
                        if( !$result )
793
                        {
794
                                $error .= "Could not insert board_startdate :: " . $sql . " :: " . __LINE__ . " :: " . __FILE__ . "<br /><br />";
795
                        }
796
797
                        $sql = "INSERT INTO " . $table_prefix . "config (config_name, config_value) 
798
                                VALUES ('default_lang', '" . str_replace("\'", "''", $language) . "')";
799
                        $result = $db->sql_query($sql);
800
                        if( !$result )
801
                        {
802
                                $error .= "Could not insert default_lang :: " . $sql . " :: " . __LINE__ . " :: " . __FILE__ . "<br /><br />";
803
                        }
804
                        $sql = "UPDATE " . $table_prefix . "config
805
                                SET config_value = '" . $server_name . "' 
806
                                WHERE config_name = 'server_name'";
807
                        $result = $db->sql_query($sql);
808
                        if( !$result )
809
                        {
810
                                $error .= "Could not update Board info :: " . $sql . " :: " . __LINE__ . " :: " . __FILE__ . "<br /><br />";
811
                        }
812
                        $sql = "UPDATE " . $table_prefix . "config
813
                                SET config_value = '" . $server_port . "' 
814
                                WHERE config_name = 'server_port'";
815
                        $result = $db->sql_query($sql);
816
                        if( !$result )
817
                        {
818
                                $error .= "Could not update Board info :: " . $sql . " :: " . __LINE__ . " :: " . __FILE__ . "<br /><br />";
819
                        }
820
                        $sql = "UPDATE " . $table_prefix . "config
821
                                SET config_value = '" . $script_path . "' 
822
                                WHERE config_name = 'script_path'";
823
                        $result = $db->sql_query($sql);
824
                        if( !$result )
825
                        {
826
                                $error .= "Could not update Board info :: " . $sql . " :: " . __LINE__ . " :: " . __FILE__ . "<br /><br />";
827
                        }
828
                        $sql = "UPDATE " . $table_prefix . "config
829
                                SET config_value = '" . $board_email . "' 
830
                                WHERE config_name = 'board_email'";
831
                        $result = $db->sql_query($sql);
832
                        if( !$result )
833
                        {
834
                                $error .= "Could not update Board info :: " . $sql . " :: " . __LINE__ . " :: " . __FILE__ . "<br /><br />";
835
                        }
836
                        $sql = "UPDATE " . $table_prefix . "config
837
                                SET config_value = '" . $server_name . "' 
838
                                WHERE config_name = 'cookie_domain'";
839
                        $result = $db->sql_query($sql);
840
                        if( !$result )
841
                        {
842
                                $error .= "Could not update Board info :: " . $sql . " :: " . __LINE__ . " :: " . __FILE__ . "<br /><br />";
843
                        }
844
                        
845
846
                        $admin_pass_md5 = ( $confirm && $userdata['user_level'] == ADMIN ) ? $admin_pass1 : md5($admin_pass1);
847
848
                        $sql = "UPDATE " . $table_prefix . "users 
849
                                SET username = '" . str_replace("\'", "''", $admin_name) . "', user_password='" . str_replace("\'", "''", $admin_pass_md5) . "', user_lang = '" . str_replace("\'", "''", $language) . "', user_email='" . str_replace("\'", "''", $board_email) . "'
850
                                WHERE username = 'Admin'";
851
                        $result = $db->sql_query($sql);
852
                        if( !$result )
853
                        {
854
                                $error .= "Could not update admin info :: " . $sql . " :: " . __LINE__ . " :: " . __FILE__ . "<br /><br />";
855
                        }
856
857
                        $sql = "UPDATE " . $table_prefix . "users 
858
                                SET user_regdate = " . time();
859
                        $result = $db->sql_query($sql);
860
                        if( !$result )
861
                        {
862
                                $error .= "Could not update user_regdate :: " . $sql . " :: " . __LINE__ . " :: " . __FILE__ . "<br /><br />";
863
                        }
864
865
                        //
866
                        // Change session table to HEAP if MySQL version matches
867
                        //
868
                        if( preg_match("/^mysql/", $dbms) )
869
                        {
870
                                $sql = "SELECT VERSION() AS mysql_version";
871
                                if($result = $db->sql_query($sql))
872
                                {
873
                                        $row = $db->sql_fetchrow($result);
874
                                        $version = $row['mysql_version'];
875
876
                                        if( preg_match("/^(3\.23)|(4\.)/", $version) )
877
                                        {
878
                                                $sql = "ALTER TABLE " . $table_prefix . "sessions 
879
                                                        TYPE=HEAP";
880
                                                $db->sql_query($sql);
881
                                        }
882
                                }
883
                        }
884
885
                        if( $error != "" )
886
                        {
887
                                $template->assign_block_vars("switch_error_install", array());
888
889
                                $template->assign_vars(array(
890
                                        "L_ERROR_TITLE" => $lang['Installer_Error'],
891
                                        "L_ERROR" => $lang['Install_db_error'] . '<br /><br />' . $error)
892
                                );
893
894
                                $template->pparse('body');
895
896
                                exit;
897
                        }
898
                }
899
900
                if( !$reinstall && !$upgrade_now )
901
                {
902
                        $template->assign_block_vars("switch_common_install", array());
903
904
                        //
905
                        // Write out the config file.
906
                        //
907
                        $config_data = '<?php'."\n\n";
908
                        $config_data .= "//\n// phpBB 2.x auto-generated config file\n// Do not change anything in this file!\n//\n\n";
909
                        $config_data .= '$dbms = "' . $dbms . '";' . "\n\n";
910
                        $config_data .= '$dbhost = "' . $dbhost . '";' . "\n";
911
                        $config_data .= '$dbname = "' . $dbname . '";' . "\n";
912
                        $config_data .= '$dbuser = "' . $dbuser . '";' . "\n";
913
                        $config_data .= '$dbpasswd = "' . $dbpasswd . '";' . "\n\n";
914
                        $config_data .= '$table_prefix = "' . $table_prefix . '";' . "\n\n";
915
                        $config_data .= 'define(\'PHPBB_INSTALLED\', true);'."\n\n";        
916
                        $config_data .= '?' . '>'; // Done this to prevent highlighting editors getting confused!
917
918
                        @umask(0111);
919
                        $no_open = FALSE;
920
921
                        $fp = @fopen('config.'.$phpEx, 'w');
922
                        if( !$fp )
923
                        {
924
                                //
925
                                // Unable to open the file writeable do something here as an attempt
926
                                // to get around that...
927
                                //
928
                                $s_hidden_fields = '<input type="hidden" name="config_data" value="' . htmlspecialchars($config_data) . '" />';
929
930
                                if( extension_loaded('ftp') && !defined('NO_FTP') )
931
                                {
932
                                        $template->assign_block_vars('switch_ftp_option', array());
933
934
                                        $lang['Unwriteable_config'] .= '<p>' . $lang['ftp_option'] . '</p>';
935
936
                                        $template->assign_vars(array(
937
                                                "L_CHOOSE_FTP" => $lang['ftp_choose'],
938
                                                "L_ATTEMPT_FTP" => $lang['Attempt_ftp'],
939
                                                "L_SEND_FILE" => $lang['Send_file'])
940
                                        );
941
                                }
942
                                else
943
                                {
944
                                        $s_hidden_fields .= '<input type="hidden" name="send_file" value="1" />';
945
                                }
946
                                if( $upgrade == 1 )
947
                                {
948
                                        $s_hidden_fields .= '<input type="hidden" name="upgrade" value="1" />';
949
                                        $s_hidden_fields .= '<input type="hidden" name="dbms" value="'.$dbms.'" />';
950
                                        $s_hidden_fields .= '<input type="hidden" name="prefix" value="'.$table_prefix.'" />';
951
                                        $s_hidden_fields .= '<input type="hidden" name="dbhost" value="'.$dbhost.'" />';
952
                                        $s_hidden_fields .= '<input type="hidden" name="dbname" value="'.$dbname.'" />';
953
                                        $s_hidden_fields .= '<input type="hidden" name="dbuser" value="'.$dbuser.'" />';
954
                                        $s_hidden_fields .= '<input type="hidden" name="dbpasswd" value="'.$dbpasswd.'" />';
955
                                        $s_hidden_fields .= '<input type="hidden" name="install_step" value="1" />';
956
                                        $s_hidden_fields .= '<input type="hidden" name="admin_pass1" value="1" />';
957
                                        $s_hidden_fields .= '<input type="hidden" name="admin_pass2" value="1" />';
958
                                        $s_hidden_fields .= '<input type="hidden" name="server_port" value="'.$server_port.'" />';
959
                                        $s_hidden_fields .= '<input type="hidden" name="server_name" value="'.$server_name.'" />';
960
                                        $s_hidden_fields .= '<input type="hidden" name="script_path" value="'.$script_path.'" />';
961
                                        $s_hidden_fields .= '<input type="hidden" name="board_email" value="'.$board_email.'" />';
962
963
                                        $template->assign_block_vars("switch_upgrade_install", array());
964
                                        $template->assign_vars(array(
965
                                                "L_UPGRADE_INST" => $lang['continue_upgrade'],
966
                                                "L_UPGRADE_SUBMIT" => $lang['upgrade_submit'])
967
                                        );
968
                                }
969
970
                                $template->assign_vars(array(
971
                                        "L_INSTRUCTION_TEXT" => $lang['Unwriteable_config'],
972
                                        "L_SUBMIT" => $lang['Download_config'],
973
974
                                        "S_HIDDEN_FIELDS" => $s_hidden_fields, 
975
                                        "S_FORM_ACTION" => "install.$phpEx")
976
                                );
977
978
                                $template->pparse('body');
979
980
                                exit;
981
                        }
982
983
                        $result = @fputs($fp, $config_data, strlen($config_data));
984
985
                        @fclose($fp);
986
                        $upgrade_now = $lang['upgrade_submit'];
987
                }
988
                else
989
                {
990
                        $template->assign_block_vars("switch_common_install", array());
991
                }
992
993
                // 
994
                // First off let's check and see if we are supposed to be doing an upgrade.
995
                //
996
                if ( $upgrade == 1 && $upgrade_now == $lang['upgrade_submit'] )
997
                {
998
                        define('INSTALLING', true);
999
                        require('upgrade.'.$phpEx);
1000
                        exit;
1001
                }
1002
                //
1003
                // Ok we are basically done with the install process let's go on 
1004
                // and let the user configure their board now.
1005
                //
1006
                // We are going to do this by calling the admin_board.php from the
1007
                // normal board admin section.
1008
                //
1009
                if( !$reinstall )
1010
                {
1011
                        $s_hidden_fields = '<input type="hidden" name="username" value="' . $admin_name . '" />';
1012
                        $s_hidden_fields .= '<input type="hidden" name="password" value="' . $admin_pass1 . '" />';
1013
                        $s_hidden_fields .= '<input type="hidden" name="redirect" value="admin/index.php" />';
1014
                        $s_hidden_fields .= '<input type="hidden" name="login" value="true" />';
1015
                }
1016
                else
1017
                {
1018
                        $s_hidden_fields = "";
1019
                }
1020
1021
                $template->assign_vars(array(
1022
                        "L_INSTRUCTION_TEXT" => $lang['Inst_Step_2'],
1023
                        "L_SUBMIT" => $lang['Finish_Install'],
1024
1025
                        "S_HIDDEN_FIELDS" => $s_hidden_fields, 
1026
                        "S_FORM_ACTION" => ( $reinstall ) ? append_sid("login.$phpEx") : "login.$phpEx")
1027
                );
1028
                
1029
                $template->pparse('body');
1030
1031
                exit;
1032
        }
1033
}
1034
1035
?>